I have followed the recommendations of other answers on SO, but still Eclipse will not build my threaded application:
#include <thread>
#include <iostream>
void func() {
std::cout << "Hello thread!" << std::endl;
}
int main() {
std::thread t(func);
t.join();
return 0;
}
Here are the commands Eclipse is using (emphasis mine):
g++ -O0 -g3 -Wall -c -fmessage-length=0 -pthread -std=c++11 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
g++ -pthread -std=c++11 -o "sandbox" ./main.o
As you can see, I added -pthread and -std=c++11. Still, Eclipse complains at run-time:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Also, building manually fails:
$ g++ main.cpp -o main.out -pthread -std=c++11
$ ./main.out
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted
What else can I do?