Error:Enable multithreading to use std::thread: Operation not permitted

解决方法: 增加 -Wl,–no-as-needed 选项
terminate called after throwing an instance of ‘std::system_error’
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted

今天在使用c++11的thread库编写代码测试的时候,编译.cpp文件后,执行对应的可执行文件的时候出现上述错误
情况如下:在这里插入图片描述
使用编译命令如下:
g++ cthread.cpp -o cthread -std=c++11
上面问题出现是由于编译器导致的:
解决方法,编译时增加 -Wl,–no-as-needed 选项:
eg:g++ -std=c++11 -pthread -Wl,–no-as-needed cthread.cpp -o cthread

注:-Wl (最后一个是小写的字母L)

你可能感兴趣的:(C/C++)