为了账号安全,请及时绑定邮箱和手机立即绑定

在linux下的GCC中使用std :: thread的正确链接选项是什么?

在linux下的GCC中使用std :: thread的正确链接选项是什么?

C++
慕容708150 2019-08-27 16:18:15
在linux下的GCC中使用std :: thread的正确链接选项是什么?嗨,我正在尝试使用std::threadG ++。这是我的测试代码#include <thread>#include <iostream>int main(int, char **){     std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });     tt.join();}它编译,但当我尝试运行它时,结果是:terminate called after throwing an instance of 'std::system_error'   what():  Operation not permitted  Aborted我的编译器版本:$ g++ --version g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1Copyright (C) 2011 Free Software Foundation, Inc.This is free software; see the source for copying conditions.  There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.我的测试代码出了什么问题?更新:我使用以下命令行来编译和运行我的代码。$ g++ -std=c++0x test.cpp $ ./a.out我试过$ g++ -std=c++0x -lpthread test.cpp $ ./a.out还是一样。
查看完整描述

3 回答

?
宝慕林4294392

TA贡献2021条经验 获得超8个赞

我认为在Linux上使用pthread实现std::thread所以你需要指定-pthread编译器选项。

由于这是一个连接选项,这个编译器选项必须是AFTER源文件:

$ g++ -std=c++0x test.cpp -pthread


查看完整回答
反对 回复 2019-08-27
?
慕后森

TA贡献1802条经验 获得超5个赞

除了使用-std=c++0x-pthread不能使用-static


查看完整回答
反对 回复 2019-08-27
  • 3 回答
  • 0 关注
  • 1255 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信