Ruler501SabayonVM Rationals # g++ -static -static-libgcc -static-libstdc++
-g -O0 -o obj/primitive --std=c++11 testcase.cpp -pthread
&& cd obj && ./primitive 8
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
Aborted我以前注意到了这个错误,但是我已经链接到它了,所以我认为我不应该有这个错误。
请注意,我在一台非常老的计算机上运行这个程序,因为我没有能力在上面安装软件包,所以glibc版本根本不支持用于线程处理的C++11。
我得到这个错误的测试是
#include<iostream>
#include<thread>
void hello(){
std::cout<< "Hello Concurrent World\n";
}
int main() {
std::thread t(hello);
t.join();
}发布于 2014-08-26 23:30:00
问题是libp线程没有被使用,所以真正的pthread_create没有链接到,而您的程序只是在glibc中调用存根pthread_create,它返回EPERM。
解决方案是强制链接器使用libp线程中的所有符号,即使它认为不需要它们,这是通过以下方式完成的:
-Wl,--whole-archive -lpthread -Wl,--no-whole-archive(注:-lpthread而非-pthread)
https://stackoverflow.com/questions/25516343
复制相似问题