8

I am running Ubuntu 14.04.

Steps I took to reproduce:

  1. Create a new C++ project (New -> C++ -> Hello World project), which I called TestStdThread

  2. 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;
    }
    
  3. Go to TestStdThread -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler, and change the Command options from g++ to g++ -std=c++11

  4. 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)

  5. 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)

  6. TestStdThread -> Build Project

  7. 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
tckmn
  • 57,719
  • 27
  • 114
  • 156
  • `#include ` maybe ? – vsoftco Jul 18 '14 at 23:33
  • @vsoftco Whoops, that was a copy/paste error. I did indeed have that in my original code, of course ;) – tckmn Jul 18 '14 at 23:35
  • Try to re-index the project. – vsoftco Jul 18 '14 at 23:41
  • @vsoftco Tried that; it still doesn't work. – tckmn Jul 18 '14 at 23:44
  • works on my end (`OS X` `gcc 4.9`), no red markings, however I added the `-std=c++11` flag under Project Properties/C++ Build/Settings/GCC C++ Compiler/Miscellaneous (Other flags), but I guess it shouldn't make any difference. – vsoftco Jul 19 '14 at 00:00
  • @vsoftco Tried that; still no luck :/ Are you on Ubuntu as well? (edit) Oh, hmm. It may be an ubuntu-specific issue then; I have no idea what could be causing that though – tckmn Jul 19 '14 at 00:04

1 Answers1

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.

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.

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

codestation
  • 2,938
  • 1
  • 22
  • 22