Eclipse c++11 线程支持不起作用
Eclipse c++11 thread support not working
我已经遵循了关于SO的其他答案的建议,但Eclipse仍然不会构建我的线程应用程序:
#include <thread>
#include <iostream>
void func() {
std::cout << "Hello thread!" << std::endl;
}
int main() {
std::thread t(func);
t.join();
return 0;
}
以下是 Eclipse 正在使用的命令(强调我的):
g++ -O0 -g3 -Wall -c -fmessage-length=0 -pthread -std=c++11 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../主.cpp"
g++ -pthread -std=c++11 -o "sandbox" ./main.o
如您所见,我添加了 -pthread 和 -std=c++11。 尽管如此,Eclipse在运行时抱怨:
在抛出"std::system_error"
实例后终止调用 what(): 启用多线程以使用 std::thread: 操作不 允许
此外,手动构建会失败:
$ g++ main.cpp -o main.out -pthread -std=c++11
$ ./main.out
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted
我还能做什么?
答案是将以下内容添加到两个位置:
-Wl,--no-as-needed
应将其添加到:
1) 项目属性 -> C/C++ 构建 ->设置 -> 工具设置 -> GCC C++编译器 -> 杂项 -> 其他标志
示例:-c -fmessage-length=0 -pthread -std=c++11 -Wl,--no-as-needed
2) 项目属性 -> C/C++ 生成 ->设置 -> 工具设置 -> GCC C++链接器 -> 杂项 -> 链接器标志
示例:-pthread -std=c++11 -Wl,--no-as-needed
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- Eclipse c++11 线程支持不起作用