在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
- 3 回答
- 0 關注
- 1350 瀏覽
添加回答
舉報
0/150
提交
取消