Eclipse 内容辅助无法识别 std::thread,但编译正确
Eclipse content assist doesn't recognize std::thread, but compiles correctly
我使用的是Ubuntu 14.04。
复制步骤:
-
创建一个新的c++项目(new -> c++ -> Hello World project),我称之为
TestStdThread
-
将主文件中的代码更改为:
#include <thread> #include <iostream> int main() { std::cout << "You have " << std::thread::hardware_concurrency() << " cores." << std::endl; return 0; }
-
进入TestStdThread -> Properties -> C/c++ Build -> Settings -> GCC c++ Compiler,将Command选项从
g++
改为g++ -std=c++11
-
进入TestStdThread -> Properties -> C/c++ Build -> Settings -> GCC c++ Compiler -> Includes,将
/usr/include
添加到Include路径(-i),并将pthread.h
添加到Include文件(- Include) -
进入TestStdThread -> Properties -> C/c++ Build -> Settings -> GCC c++ Linker -> Libraries,将
pthread
添加到Libraries (-l),并将/usr/lib/x86_64-linux-gnu
添加到Library搜索路径(-l) -
TestStdThread -> Build Project
-
点击"运行"
没有构建错误。Eclipse告诉我项目有错误,并询问我是否要运行它,当我说是时,输出是正确的:You have 4 cores.
。然而,Eclipse仍然用红色标注std::thread::hardware_concurrency
部分,并报告它为"Function 'hardware_concurrency'无法解析",并且当输入std::
Ctrl+Space时,std::thread
没有显示。
这是我用来找到我的pthread
文件位于/usr
(/usr/share
省略,因为它包含了很多我不寻找的文档文件)的bash命令:
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
进入Project
-> Properties
-> C/C++ General
-> Preprocessor include paths, etc
-> Providers
-> CDT GCC Builtin Compiler Settings
,并将-std=c++11
添加到编译器规范中。
您也可以为所有项目执行Window
-> Preferences
-> C/C++
-> Build
-> Settings
-> Discovery
,并将-std=c++11
附加到CDT GCC Builtin Compiler Settings
规范。
一定要在之后重新索引你的项目。
这些说明适用于Eclipse Luna(4.4.0),对于以前的版本,路径是类似的。