gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 00:39:12 25 4
gpt4 key购买 nike

我试图让线程在 Ubuntu 下的 Qt Creator 中工作。我设置了

QMAKE_CXXFLAGS += -std=c++11 -pthread -lpthread  
CXXFLAGS += -std=c++11 -pthread -lpthread

但是还是不行,会写

terminate called after throwing an instance of ‘std::system_error’ 
what(): Operation not permitted

我尝试编译的文件是这个

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

void fun(){
}

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

最佳答案

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

LIBS += -pthread

所以它现在可以用这两行

QMAKE_CXXFLAGS = -std=c++11 
LIBS += -pthread

关于Qt Creator 2.7.0 (Qt 5.0.2) 中的 C++11 线程支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16599287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com