【发布时间】:2013-10-30 04:36:10
【问题描述】:
这是 ubuntu 13.10 和 g++ 4.8 的错误,所以我关闭了这个问题。
within -Wl,--no-as-needed.
我的脑袋有问题。 我有一些类似的代码
#include <iostream>
#include <thread>
int main(int argc, char* argv[])
{
{
std::thread t1([&]{ std::cout << "hello " << std::endl; });
t1.join();
}
return 0;
}
这是我的编译命令:
g++ -std=c++0x -lpthread test.cpp
ps:我已经更改了所有类型的链接顺序。
它适用于 g++ 4.7 和 ubuntu 13.04 但它会在 g++ 4.8.1 和 ubuntu 12.10 上引发 system_error
直到我用 -fprofile-arcs 编译它运行良好。
就在下面:
g++ test.cpp -std=c++0x -fprofile-arcs -pthread
a.out
hello
g++ test.cpp -std=c++0x -pthread
a.out
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not allowed
【问题讨论】:
-
编译或链接是否失败?
-
假设是链接,导致运行时出错
-
编译为
g++ -std=c++0x test.cpp -lpthread时工作正常。编译为g++ -std=c++0x -lpthread test.cpp时抛出“操作不允许”系统异常 -
仍然“不允许操作”
-
你需要使用编译器标志
-pthred(不要用-lpthread链接到libpthread)。
标签: c++ multithreading c++11 compiler-construction