亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在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 關注
  • 1350 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號