【发布时间】:2014-08-25 20:54:41
【问题描述】:
我的问题是:如果我用 c++11 线程编译和链接我的多线程应用程序使用我自己的 makefile 和 GCC 编译器(我在 Ubuntu 上工作),所有工作正常。程序运行正确。
(我使用 -pthreads 和 -std=c++11 都很好用)
但是如果我想在 IDE 中创建项目(netbeans 或 QT 在 c++11 上设置标准)并使用 IDE 生成的 makefile 编译我的源代码(只需点击按钮“BUILD”),在运行我收到的执行文件时:
在抛出 'std::system_error' 的实例后调用终止 what():启用多线程以使用 std::thread:不允许操作
我知道这是关于这个错误的答案,但是它们与 g++ 编译器有关。我的编译器工作正常,但我的 IDE 有问题。 PS:在 Netbeans 我添加 -pthread 来编译标志
【问题讨论】:
-
看来您并没有真正将
-pthread添加到命令行。让 Netbeans 打印它调用 g++ 的命令行。 -
在输出中 g++ -pthread -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux-x86/main .o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp mkdir -p dist/Debug/GNU-Linux-x86 我真的 g++ -pthread -o dist/Debug/GNU-Linux-x86/ 123 构建/调试/GNU-Linux-x86/main.o
-
我认为你会发现这个对话很有用:forums.netbeans.org/ntopic9511.html
-
我在“附加选项”中添加了-pthread
-
执政官,亚历山德罗 - 谢谢。我再做一次,一切都很好。
标签: c++ multithreading c++11 ide