Reputation: 4990
I am trying to make threads work in Qt Creator under Ubuntu. I set the
QMAKE_CXXFLAGS += -std=c++11 -pthread -lpthread
CXXFLAGS += -std=c++11 -pthread -lpthread
but it still wont work and will write
terminate called after throwing an instance of ‘std::system_error’
what(): Operation not permitted
The file I try to compile is this
#include <iostream>
#include <thread>
using namespace std;
void fun(){
}
int main()
{
thread th(&fun);
cout << "Hello World!" << endl;
return 0;
}
Upvotes: 2
Views: 2890
Reputation: 4990
I had to add the following line to the myProject.pro file
LIBS += -pthread
so it works now with these two lines
QMAKE_CXXFLAGS = -std=c++11
LIBS += -pthread
Upvotes: 5