在linux下的GCC中使用std :: thread的正确链接选项是什么? [英] What is the correct link options to use std::thread in GCC under linux?
本文介绍了在linux下的GCC中使用std :: thread的正确链接选项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我试图使用 std :: thread
与G ++。这是我的测试代码
#include< thread>
#include< iostream>
int main(int,char **){
std :: thread tt([](){std :: cout<<Thread!< std: :endl;});
tt.join();
}
它编译,但是当我尝试运行它时,结果是: p>
在抛出'std :: system_error'实例后调用terminate
what():不允许操作
已中止
我的编译器版本:
$ g ++ --version
g ++(Ubuntu / Linaro 4.6.1-9ubuntu3)4.6.1
版权所有(C)2011自由软件基金会
这是免费软件;请参阅复制条件的来源。有NO
保修;甚至不适用于适销性或特定用途的适用性。
我的测试代码有什么问题?
UPDATE:我使用以下命令行编译和运行我的代码。
$ g ++ -std = c ++ 0x test.cpp
$ ./a.out
我尝试了
$ g ++ -std = c ++ 0x -lpthread test.cpp
$ ./a.out
$
更新:以下compile命令可以工作。
/ p>
$ g ++ -std = c ++ 0x test.cpp -lpthread
$ ./a.out
线程!
解决方案我认为在Linux pthread用于实现 std :: thread
,因此您需要指定 -pthread
编译器选项。
Hi I am trying to use std::thread
with G++. Here is my test code
#include <thread>
#include <iostream>
int main(int, char **){
std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });
tt.join();
}
It compiles, but when I try to run it the result is:
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted
My compiler version:
$ g++ --version
g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (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.
What is wrong with my test code?
UPDATE: I use the following command line to compile and run my code.
$ g++ -std=c++0x test.cpp
$ ./a.out
and I tryed
$ g++ -std=c++0x -lpthread test.cpp
$ ./a.out
still the same.
UPDATE: the following compile command works.
$ g++ -std=c++0x test.cpp -lpthread
$ ./a.out
Thread!
解决方案 I think on Linux pthread is used to implement std::thread
so you need to specify the -pthread
compiler option.
这篇关于在linux下的GCC中使用std :: thread的正确链接选项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文