Reputation: 41
My problem is actually described here: Compiling multithread code with g++. But the answer regarding the work around by using "-Wl,--no-as-needed" is not working for me.
I've added -Wl,--no-as-needed -pthread -std=c++0x
in different orders also, but I still get the:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted"
What to do?
Info:
Ubuntu 12.04LTS
Running Eclipse CDT
g++ v4.8.1
Edit:
I tried building with -Wl,--no-as-needed -lpthread -std=c++0x
with no luck.
The code:
#include <iostream>
#include <chrono>
#include <thread>
void foo()
{
std::cout << "Thread 1 created.." << std::endl;
}
int main()
{
std::thread t1(foo);
t1.join();
return 0;
}
Edit: So unfortunately none of your suggestions worked. I decided to use Boost instead.
Upvotes: 4
Views: 6933
Reputation: 362
g++ filename.c -std=c++11 -lpthread
i am compiling your code with above command its working perfect.
Upvotes: 1
Reputation: 9811
-Wl,--no-as-needed
not -Wl,--no_as_needed
, you use the hyphen-pthread
is a flag for the compiler, not the linker, the right one for the linker is -lpthread
Upvotes: 4