Eclipse内容辅助无法识别std :: thread,但可以正确编译 [英] Eclipse content assist doesn't recognize std::thread, but compiles correctly

查看:155
本文介绍了Eclipse内容辅助无法识别std :: thread,但可以正确编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行Ubuntu 14.04。

I am running Ubuntu 14.04.

我复制的步骤:


  1. 创建一个新的C ++项目(新建-> C ++-> Hello World项目),我将其称为 TestStdThread

将主文件中的代码更改为此:

Change the code in the main file to this:

#include <thread>
#include <iostream>

int main() {
    std::cout << "You have " << std::thread::hardware_concurrency() << " cores." << std::endl;
    return 0;
}


  • 转到TestStdThread->属性-> C / C ++构建- >设置-> GCC C ++编译器,然后将命令选项从 g ++ 更改为 g ++ -std = c ++ 11

    转到TestStdThread->属性-> C / C ++构建->设置-> GCC C ++编译器->包括,添加 / usr / include 包含路径(-I),并添加 pthread.h 转到包含文件(-包括)

    Go to TestStdThread -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Includes, add /usr/include to the Include paths (-I), and add pthread.h to the Include files (-include)

    转到TestStdThread->属性-> C / C ++构建->设置- > GCC C ++链接器->库,将 pthread 添加到库(-l),然后添加 / usr / lib / x86_64-linux-gnu 库搜索路径(-L)

    Go to TestStdThread -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Libraries, add pthread to the Libraries (-l), and add /usr/lib/x86_64-linux-gnu to the Library search path (-L)

    TestStdThread->构建项目

    TestStdThread -> Build Project

    单击运行

    没有构建错误。 Eclipse告诉我该项目有错误,并询问我是否仍要运行它,当我说是时,输出正确是:您有4个内核。。但是,Eclipse仍然用红色强调了 std :: thread :: hardware_concurrency 部分,并在悬停时报告为无法解析功能'hardware_concurrency',并且键入 std :: Ctrl + <时未显示 std :: thread kbd> Space 。

    There were no build errors. Eclipse told me that the project had errors and asked if I wanted to run it anyway, and when I said yes, the output was, correctly: You have 4 cores.. However, Eclipse still underlined the std::thread::hardware_concurrency part in red, and reported it (on hover) as "Function 'hardware_concurrency' could not be resolved," and std::thread didn't show up when typing std:: Ctrl+Space.

    这是我用来查找 pthread 文件所在位置的bash命令位于 / usr / usr / share 内,因为它包含许多我不需要的文档文件):

    This is the bash command I used to find where my pthread files were located within /usr (/usr/share omitted as it contains lots of doc files that I'm not looking for):

    llama@llama-Satellite-E55-A:/usr$ find -name "*pthread*" -not -path "./share/*"
    ./include/pthread.h
    ./include/x86_64-linux-gnu/bits/pthreadtypes.h
    ./lib/x86_64-linux-gnu/pkgconfig/pthread-stubs.pc
    ./lib/x86_64-linux-gnu/libpthread.so
    ./lib/x86_64-linux-gnu/libpthread_nonshared.a
    ./lib/x86_64-linux-gnu/libgpgme-pthread.so.11.11.0
    ./lib/x86_64-linux-gnu/libgpgme-pthread.so.11
    ./lib/x86_64-linux-gnu/libpthread.a
    ./lib/perl/5.18.2/bits/pthreadtypes.ph
    ./lib/debug/lib/x86_64-linux-gnu/libpthread-2.19.so
    


    推荐答案

    转到项目-> 属性-> C / C ++常规-> 预处理器包括路径等-> 提供程序-> CDT GCC内置编译器设置并附加 -std = c + +11 符合编译器规范。

    Go to Project -> Properties -> C/C++ General -> Preprocessor include paths, etc -> Providers -> CDT GCC Builtin Compiler Settings and append -std=c++11 to the compiler specs.

    您也可以为所有要转到 Window -> 首选项-> C / C ++ -> 构建-> 设置-> 发现,并附加 -std = c ++ 11 CDT GCC内置编译器设置规范。

    You can also do this for all projects going to Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery and append -std=c++11 to the CDT GCC Builtin Compiler Settings specs.

    请确保为项目重新编制索引

    Make sure to reindex your project afterwards.

    这些说明适用于Eclipse Luna(4.4.0),对于以前的版本,路径相似。

    These instructions are for Eclipse Luna (4.4.0), for previous versions the paths are similar.

    这篇关于Eclipse内容辅助无法识别std :: thread,但可以正确编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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