C++ cpp线程程序可以';t在没有-fprofile弧的情况下运行
这是来自ubuntu 13.10和g++4.8的一个bug,所以我结束了这个问题。C++ cpp线程程序可以';t在没有-fprofile弧的情况下运行,c++,multithreading,c++11,compiler-construction,C++,Multithreading,C++11,Compiler Construction,这是来自ubuntu 13.10和g++4.8的一个bug,所以我结束了这个问题。 within -Wl,--no-as-needed. 我头上有点不对劲。 我有一些类似的代码 #include <iostream> #include <thread> int main(int argc, char* argv[]) { { std::thread t1([&]{ std::cout << "hello " <<
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;
}
ps:我已经更改了所有类型的订单的链接订单
它适用于g++4.7和ubuntu 13.04
但是它在g++4.8.1和ubuntu 12.10上抛出了一个系统错误
在使用-fprofile弧编译之前,它运行良好
只需大声喊叫:
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():启用多线程以使用std::thread:不允许的操作只需跨一个Ubuntu 12.10虚拟机
osmith@ubuntu1210 ~/src $ g++-4.8 --version
g++ (Ubuntu 4.8.1-2ubuntu1~12.10) 4.8.1
Copyright (C) 2013 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.
并使用以下命令行编译:
osmith@ubuntu1210 ~/src $ g++-4.8 -std=c++11 -o test.exe test.cpp -pthread -lpthread
osmith@ubuntu1210 ~/src $ ./test.exe
hello
它在编译或链接时失败吗?假设是链接,导致错误发生在运行时,当编译为
g++-std=c++0x test.cpp-lpthread
时,工作正常。当编译为g++-std=c++0x-lpthread test时引发“不允许操作”系统异常。cpp
仍然是“不允许操作”您需要使用编译器标志-pthred
(不使用-lpthread
链接到libpthread
)。是的,对于我的ubuntu 13.04也可以,但在13.10中运行fialue。
osmith@ubuntu1210 ~/src $ g++-4.8 -std=c++11 -o test.exe test.cpp -pthread -lpthread
osmith@ubuntu1210 ~/src $ ./test.exe
hello