【问题标题】:Thread c++11 standard and Netbeans/Other IDE线程 c++11 标准和 Netbeans/其他 IDE
【发布时间】: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


【解决方案1】:

项目属性->构建->c++编译器 ->编译行->附加选项 单击“附加选项”右侧的这个小按钮并添加“-pthread”

【讨论】:

    猜你喜欢
    • 2016-03-28
    • 2011-04-16
    • 1970-01-01
    • 2013-08-05
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多