Qt Creator 2.7.0(Qt 5.0.2)中的C++ 11线程支持

Sla*_*zer 2 c++ ubuntu qt multithreading c++11

我试图让线程在Ubuntu下的Qt Creator中运行.我订了

QMAKE_CXXFLAGS += -std=c++11 -pthread -lpthread  
CXXFLAGS += -std=c++11 -pthread -lpthread
Run Code Online (Sandbox Code Playgroud)

但它仍然不会工作,会写

terminate called after throwing an instance of ‘std::system_error’ 
  what(): Operation not permitted
Run Code Online (Sandbox Code Playgroud)

我尝试编译的文件就是这个

#include <iostream>
#include <thread>
using namespace std;

void fun(){
}

int main()
{
    thread th(&fun);
    cout << "Hello World!" << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Sla*_*zer 5

我必须将以下行添加到myProject.pro文件中

LIBS += -pthread
Run Code Online (Sandbox Code Playgroud)

所以它现在与这两行一起工作

QMAKE_CXXFLAGS = -std=c++11 
LIBS += -pthread
Run Code Online (Sandbox Code Playgroud)

  • **编译器标志!=链接器标志**LIBS向链接器添加标志,QMAKE_CXXFLAGS或CXXFLAGS向编译器添加标志! (2认同)