So I've been trying to get the following code to compile and run on Windows by using a MinGW compiler.
#include <iostream>
#include <thread>
#include <future>
void ThreadWork(std::promise<int> &&p)
{
// Pre-return from thread, do work after returning a value
/* if else and things */ p.set_value(0);
std::cout << "From thread" << std::endl;
// More work
}
int main()
{
std::promise<int> p;
std::future<int> f = p.get_future();
std::thread th(ThreadWork, std::move(p));
// Get return value from thread
int ret = f.get();
}
The above gives the error:
error: aggregate 'std::promise<int> p' has incomplete type and cannot be defined
75 | std::promise<int> p;
error: variable 'std::future<int> f' has initializer but incomplete type
76 | std::future<int> f = p.get_future();
error: 'thread' is not a member of 'std'
77 | std::thread th(readInThread, callback, std::move(p));
Tried using official MinGW build, Tried using meganz/mingw-std-threads (that seem to throw errors like _WIN32_WININT
is not set even though it is set to 0x0A00, if I try to set it manually compilation fails with redeclaration), and many more, succeed in none...
I also tried to link with pthreads: -lpthread
no luck :(
Why are C++11 standard features still not implemented in MinGW? And what's the alternative for them currently?
Aucun commentaire:
Enregistrer un commentaire