我的问题实际上是在这里描述的:使用g++编译多线程代码 https://stackoverflow.com/questions/19463602/compiling-multithread-code-with-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
Edit:我尝试用-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。
- it's
-Wl,--no-as-needed
not -Wl,--no_as_needed
,您使用连字符
-
-pthread
是编译器的标志,而不是链接器的标志,链接器的正确标志是-lpthread
- Mingw 并不总是附带相同的线程库,MinGW 有不止 1 个多线程选项,您应该根据您的 MinGW 构建自行记录这一点
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)