使用g++编译多线程代码(-Wl,--no根据需要不工作)
Compiling multithread code with g++ (-Wl,--no-as-needed NOT working)
我的问题实际上在这里描述:用g++编译多线程代码。但是,关于使用"-Wl,--no as needed"解决问题的答案对我不起作用
我也在不同的订单中添加了-Wl,--no-as-needed -pthread -std=c++0x
,但我仍然得到:
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted"
该怎么办?
Info:
Ubuntu 12.04LTS
Running Eclipse CDT
g++ v4.8.1
编辑:我尝试用-Wl,--no-as-needed -lpthread -std=c++0x
进行构建,但没有成功。代码:
#include <iostream>
#include <chrono>
#include <thread>
void foo()
{
std::cout << "Thread 1 created.." << std::endl;
}
int main()
{
std::thread t1(foo);
t1.join();
return 0;
}
编辑:不幸的是,你的建议都不起作用。我决定改用Boost
- 它是
-Wl,--no-as-needed
而不是-Wl,--no_as_needed
,您使用连字符 -pthread
是编译器的标志,而不是链接器的标志,链接器的正确标志是-lpthread
- Mingw并不总是带有相同的线程库,Mingw有不止一个多线程选项,你应该根据你的Mingw构建来记录自己
g++ filename.c -std=c++11 -lpthread
我正在用上面的命令编译你的代码,它的工作非常完美。
相关文章:
- "error: no matching function for call to"构造函数错误
- QSqlquery prepare()和bindvalue()不工作
- 调用专用模板时出错"no matching function for call to [...]"
- 导入库可以跨dll版本工作吗
- 以螺旋方式打印矩阵的程序.(工作不好)
- 对象指针在c++中是如何工作的
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- 为字符串中每 N 个字符插入空格的函数没有按照我认为的方式工作?
- C++为线程工作动态地分割例程
- 为什么我的 std::ref 无法按预期工作?
- 布尔比较运算符是如何在C++中工作的
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 不确定要在我的main中放入什么才能使我的代码正常工作
- 为什么std::condition_variable notify_all的工作速度比notify_one快(对于随机请
- <<操作员在下面的行中工作
- GCC 和 clang 抛出"no matching function call"但 msvc (cl) 按预期编译和工作
- SQLite CREATE TABLE 和 INSERT 工作,但返回SQLITE_ERROR "no such table" C++
- 我的 if-else 语句中的 no 选项无法正常工作
- 使用g++编译多线程代码(-Wl,--no根据需要不工作)