【发布时间】:2014-09-10 04:28:41
【问题描述】:
我正在运行 Ubuntu 14.04。
我复制的步骤:
新建一个 C++ 项目(New -> C++ -> Hello World 项目),我称之为
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 paths (-I),并将pthread.h添加到包含文件(-include)转到 TestStdThread -> Properties -> C/C++ Build -> Settings -> GCC C++ Linker -> Libraries,将
pthread添加到 Libraries (-l),然后将/usr/lib/x86_64-linux-gnu添加到库搜索路径 (-L)TestStdThread -> 构建项目
点击“运行”
没有构建错误。 Eclipse 告诉我该项目有错误并询问我是否要运行它,当我说是时,输出正确:You have 4 cores.。但是,Eclipse 仍然用红色强调了std::thread::hardware_concurrency 部分,并将其报告为(悬停时)“无法解析函数'hardware_concurrency'”,并且在键入std:: Ctrl 时std::thread 没有出现+空格。
这是我用来查找我的 pthread 文件在 /usr 中的位置的 bash 命令(/usr/share 被省略,因为它包含很多我不需要的 doc 文件):
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
【问题讨论】:
-
#include <thread>也许? -
@vsoftco 哎呀,这是一个复制/粘贴错误。当然,我的原始代码中确实有这个;)
-
尝试重新索引项目。
-
@vsoftco 试过了;还是不行。
-
在我这边工作 (
OS Xgcc 4.9),没有红色标记,但是我在 Project Properties/C++ Build/Settings/GCC C++ Compiler/Miscellaneous (Other flags) 下添加了-std=c++11标志),但我想这应该没什么区别。
标签: c++ eclipse ubuntu eclipse-cdt stdthread