如何使CDT/Eclipse与C ++ 11线程一起使用? [英] How to make CDT/Eclipse work with C++11 threads?
问题描述
我试图在Eclipse中测试C ++ 11线程的示例.但是我在运行程序时收到了以下消息:
I tried to test an example of C++11 threads in Eclipse. But I got this message when running the program:
抛出'std :: system_error'实例后调用terminate what():不允许进行操作'
terminate called after throwing an instance of 'std::system_error' what(): Operation not permitted'
我的系统:ubuntu + gcc 4.7
My system: ubuntu + gcc 4.7
程序:
#include <iostream>
#include <thread>
void worker()
{
std::cout << "hello from worker" << std::endl;
}
int main(int argc, char **argv)
{
std::thread t(worker);
t.join();
}
...是的,我将-std=c++11
和-pthread
放在C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Miscellaneous -> Other Flags
内.
...and yes, I put -std=c++11
and -pthread
inside C/C++ Build -> Settings -> Tool Settings -> Cross G++ Compiler -> Miscellaneous -> Other Flags
.
有任何评论吗?
推荐答案
Jonathan Wakely的评论解决了这个问题.
The problem was solved by the comment of Jonathan Wakely.
我在C/C++ Build -> Settings -> Tool Settings -> Cross G++ **Linker** -> Miscellaneous -> Other Flags
中添加了-pthread
,程序正常运行.
I added -pthread
to C/C++ Build -> Settings -> Tool Settings -> Cross G++ **Linker** -> Miscellaneous -> Other Flags
and the program worked correctly.
谢谢乔纳森.
这篇关于如何使CDT/Eclipse与C ++ 11线程一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!