c++11编译错误 Enable multithreading to use std::thread: Operation not permitted

来源:互联网 发布:软件著作权 邮寄证书 编辑:程序博客网 时间:2024/06/11 22:34

最近用codenvy练习c++11,除了延时和模板少,其他还是很好用的。codenvy中默认的c++编程呢环境是ubuntu 14 + gcc 4.8.4,运行g++ -std=c++11 mai.cpp时报错:

terminate called after throwing an instance of 'std::system_error'  what():  Enable multithreading to use std::thread: Operation not permittedAborted (core dumped)

一度以为是权限问题,但是不是。google后发现,这是gcc中一个bug造成的,具体讨论点这里。

解决方案搬到这里来:

qt+gcc运行:

LIBS += -pthreadQMAKE_CXXFLAGS += -pthreadQMAKE_CXXFLAGS += -std=c++11

console g++运行:

g++ -c main.cpp -pthread -std=c++11         // generate target object file without linkg++ main.o -o main.out -pthread -std=c++11  // link to target binary或者是g++ main.cpp -pthread -std=c++11 //generate target excutable file with target object and link

如果没作用,尝试:

 g++ main.cpp  -Wl,--no-as-needed  -lpthread -std=c++11
0 0
原创粉丝点击