I am running Ubuntu 14.04.
Steps I took to reproduce:
-
Create a new C++ project (New -> C++ -> Hello World project), which I called
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; }
-
Go to TestStdThread -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler, and change the Command options from
g++
tog++ -std=c++11
-
Go to TestStdThread -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler -> Includes, add
/usr/include
to the Include paths (-I), and addpthread.h
to the Include files (-include) -
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 -> Build Project
-
Click "Run"
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.
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
Best Answer
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.You can also do this for all projects going to
Window
->Preferences
->C/C++
->Build
->Settings
->Discovery
and append-std=c++11
to theCDT GCC Builtin Compiler Settings
specs.Make sure to reindex your project afterwards.
These instructions are for Eclipse Luna (4.4.0), for previous versions the paths are similar.