如何使CDT/Eclipse与C ++ 11线程一起使用? [英] How to make CDT/Eclipse work with C++11 threads?

查看:77
本文介绍了如何使CDT/Eclipse与C ++ 11线程一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆