35

After researching this on the internet, I've been unable to get the Eclipse indexer to resolve "shared_ptr" from the C++0x additions that come with GCC 4.4.4. I made sure to create my project with the proper includes for Eclipse, so it's definitely looking in the the 4.4.4 include folders.

The program compiles and runs just fine. To access shared_ptr I'm using "#include <memory>".

Any idea what's breaking the indexer?

Dylan Klomparens
  • 2,853
  • 7
  • 35
  • 52
  • Have a look at my answer at http://stackoverflow.com/questions/13905283/eclipse-polymorphism-using-c11-shared-ptr-error/13923667#13923667http://stackoverflow.com/questions/13905283/eclipse-polymorphism-using-c11-shared-ptr-error/13923667#13923667 – Johan Lundberg Dec 17 '12 at 23:00

5 Answers5

50

You need to set the pre-processor symbol '__GXX_EXPERIMENTAL_CXX0X__' to the eclipse project. g++ automatically adds that when you use '-std=c++0x', but eclipse is not aware of that, so it treats those sections of the relevant headers as disabled.

Fred Larson
  • 60,987
  • 18
  • 112
  • 174
Dave S
  • 20,507
  • 3
  • 48
  • 68
  • Newbie question: How do I set this symbol? What do I set it to? Thanks. – Anschel Schaffer-Cohen Dec 28 '11 at 18:09
  • 7
    @AnschelSchaffer-Cohen: Project Properties - C/C++ General - Paths and Symbols - Symbols - GNU C++ – Dave S Dec 30 '11 at 13:49
  • 4
    You can add it automatically by adding -std=c++0x to the "Compiler invocation arguments" in the Discovery options of C/C++ Build in project properties. – Marco May 25 '12 at 07:10
  • 9
    @DaveS - Hi, sorry to bother you with an old question, but adding the symbol `__GXX_EXPERIMENTAL_CXX0X__` did not work for me, any other suggestions?thks in advance ;) – Matteo May 31 '12 at 07:36
  • @Matteo: I'm not sure. What version of g++ are you using? If you want, you can look at one of the C++ only headers (like forward_list), and see what it's using as a guard for only C++11 features. – Dave S May 31 '12 at 17:00
  • @DaveS - I managed to fix the problem, thks for help anyway ;) – Matteo Jun 03 '12 at 09:40
  • 3
    @Matteo How finally you did it? – remdezx Feb 15 '13 at 13:30
  • 1
    I've add the -std=c++11 flag to the C++ -> Build -> Settings -> Discovery -> CDT GCC Built-in Compiler Settings as well as adding the __GXX_EXPERIMENTAL_CXX0X__ symbol as described by @DaveS. And then for some additional "magic", closed eclipse and reopened it. That seems to fix the problem in Eclipse Luna – Langley Mar 10 '15 at 19:58
9

I experienced this problem under Windows with Eclipse 4.5.1 (Mars.1) and Cygwin 2.3.0 (GCC 4.9.3).

The indexer can't find shared_ptr because of lines like this in the <memory> header. The __cplusplus macro is evaluating to something other than C++ 11 (aka 201103) so the older auto_ptr.h is being included instead of shared_ptr.h. Why? The below screen shot of the project properties shows that C++ 98 (199711) is being detected under CDT GCC Build-in Compiler Settings.

#if __cplusplus >= 201103L
#  include <bits/shared_ptr.h>
#else
#  include <backward/auto_ptr.h>
#endif

enter image description here

There are two possible solutions to tell Eclipse to use C++ :

  • On the same Preprocessor Include Paths screen, scroll to the top of the Setting Entries area. Expand CDT User Setting Entries. Add a new Preprocessor Macro for __cplusplus=201103L. Do this for both the Release and Debug Configurations. Then rebuild the index.

  • If you want to default the CDT GCC Build-in Compiler Settings to use 201103 for all projects, then edit the language.settings.xml file (under Windows this is c:\Users\deanhill\workspace\.metadata\.plugins\org.eclipse.cdt.core\language.settings.xml). Set __cplusplus=201103L. Restart Eclipse and rebuild the index.

Dean Hill
  • 4,369
  • 6
  • 31
  • 35
4

Although I am late to the game, this is what worked for me:

Right-Click on Project->Properties->C/C++ General->Preprocessor Include Paths, Macros, etc. --> Click "Providers" tab --> CDT GCC Built-in Compiler Settings

Uncheck "Use global provider shared between projects"

Add -std=c++0x

It will then look something like this:

${COMMAND} ${FLAGS} -E -P -v -dD -std=c++0x "${INPUTS}"

Rebuild index.

Using Debian Jessie + Eclipse Kepler Build id: 20140224-0627

Makketronix
  • 1,389
  • 1
  • 11
  • 31
2

I experienced the same problem. I have added the GXX_EXPERIMENTAL_CXX0X as well as -std=c++11 to compiler options in workspace. However it did not solve my problem.

I was missing one more step: Right-Click on Project->Properties->C/C++ Build->Settings->Cross G++ Compiler->Miscellaneous->Other flags I changed -c -fmessage-length=0 to -c -fmessage-length=0 -std=c++11

Now Eclipse sees std::shared_ptr and indexes it correctly.

da-na
  • 250
  • 2
  • 8
1

For me it worked by setting other dialect flags = -std=c++11 under:

Preferences -> C++ Build -> Settings -> GCC C++ Compiler -> Dialect,

as well as adding -std=c++11 under:

Preferences -> C++ General -> Preprocessor Include Path -> Providers -> CDT GCC Build-in Compiler Settings -> command to get compiler specs.

Do not forget to clean and rebuild your Project/Index.

scopchanov
  • 7,966
  • 10
  • 40
  • 68