Eclipse CDT indexer does not know C++11 containers
Asked Answered
I

8

48

I configured a C++11 project in Eclipse CDT to use gcc-4.7. It is not the default compiler on my system, which does not support C++11. In order for compilation to work, I need to pass the flag -std=c++11 and also include the following header path: /usr/local/Cellar/gcc/4.7.2/gcc/include/c++/4.7.2

Whenever I use C++11 container types like std::unordered_set or std::unordered_map, the CDT indexer complains: Symbol unordered_set could not be resolved. How can I tell the indexer to resolve these symbols correctly?

This is how I have configured my indexer:

enter image description here

As far as I understand the settings, the indexer is supposed to use the compiler settings from the currently active build configuration. Compilation works fine, so why doesn't indexing, too?

Impi answered 16/6, 2013 at 9:15 Comment(0)
M
35

As described in this forum post:

http://www.eclipse.org/forums/index.php/mv/msg/282618/

  • right-click the project and go to "Properties" C/C++ General -> Paths and Symbols -> Symbols -> GNU C++.
  • Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__ into "Name" and leave "Value" blank. Hit Apply, do whatever it asks you to do, then hit OK.
Mike answered 16/6, 2013 at 11:8 Comment(3)
This answer was correct was older release. But going ahead (with newer versions of Eclipse) @selyuni's answer works. Trying the answer which was once a correct solution is only a waste of time. Maybe SOF can change the policy to put more upvoted answers on top than just the correct answer. :-)Minded
@VikasGoel: Does this depend on the Eclipse version, or on the compiler/library version, or both?Kimberykimble
@Kimberykimble - only Eclipse versionMinded
H
84

Setting up **__GXX_EXPERIMENTAL_CXX0X__** does not help in my case (Jul 2014, Eclipse Kepler 20130919, Ubuntu 12.04).

To fix C++11 syntax highlighting go to:

Project Properties --> C/C++ General --> Paths and Symbols --> Symbols --> GNU C++

and overwrite the symbol (i.e. add new symbol):

__cplusplus

with value

201103L

UPDATED: If you use newer version of Eclispe (as of 2016) and still experience the same problem, try value (as pointed by jose.diego):

201402L

Make sure that indexer is enabled in Project settings (C/C++ general --> Indexer)

Then reindex (Project --> C/C++ Index --> Rebuild)

if the problem still persist reindex once again. It should work now.

Hamill answered 8/7, 2014 at 8:44 Comment(7)
Although it works with plain helloworlds, it doesn't work with makefile project. Any suggestions?Spook
solved it for me too, setting up GXX_EXPERIMENTAL_CXX0X didn't work for me eitherRetroflex
@Spook see https://mcmap.net/q/352055/-eclipse-cdt-indexer-does-not-know-c-11-containers which I tested and it works for makefile projects too.Lurid
Worked for me too. Only added a __cplusplus symbol with value 201103L. I don't need to do the enabling indexer step. Previously, setting up GXX_EXPERIMENTAL_CXX0X didn't work for me eitherLafrance
setting __cplusplus to 201402L was the only thing that solved my issue in Eclipse Mars2Revalue
Works for Neon tooLigation
None of these settings are working for me. Neon / g++ 5.4.0 -- I suspect the g++ version is more relevant than the Eclipse version.Avouch
T
51

I solved this problem recently after some lucky googling.

Click on your project and right-click->Properties

Select "C/C++ General -> Processor Include Paths, Macros etc..."

Select the "Providers" tab

Deselect everything except "CDT User Setting Entries" and "CDT GCC Built-in Compiler Settings"

Click on "CDT GCC Built-in Compiler Settings"

Deselect "Use global provider shared between projects"

Edit the box at the bottom labeled "Command to get compiler specs"

Insert into the command -std=c++11 so it looks something like this:

${COMMAND} -std=c++11 -E -P -v -dD "${INPUTS}"

Click Apply and Okay.

enter image description here

That worked for me. You probably need to re-index the project.

Titular answered 8/7, 2014 at 9:57 Comment(8)
re - "probably need to re-index": my tests show "you must re-index"Lurid
I tested this with makefile projects and this solution works.Lurid
It was suffice for me to simple move GCC Built-int Compiller Settings to the very top of this listTipster
You can also set this as workspace configuration, so C++11 will be enabled in all your new projects.Margit
@Tipster thanks! In fact, just disabling "contributed pathentry containers" in that list did the trick for me.Montemontefiascone
Really thanks, only working list of steps that really worksOrthopsychiatry
As of today, doesn't work with -std=c++2x but works a treat with -std=c++17Lophobranch
@BlairHoughton That is down to the version of the compiler you are using. It doesn't have anything to do with eclipse itself. Also I think the switch will be -std=c++2a.Titular
M
35

As described in this forum post:

http://www.eclipse.org/forums/index.php/mv/msg/282618/

  • right-click the project and go to "Properties" C/C++ General -> Paths and Symbols -> Symbols -> GNU C++.
  • Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__ into "Name" and leave "Value" blank. Hit Apply, do whatever it asks you to do, then hit OK.
Mike answered 16/6, 2013 at 11:8 Comment(3)
This answer was correct was older release. But going ahead (with newer versions of Eclipse) @selyuni's answer works. Trying the answer which was once a correct solution is only a waste of time. Maybe SOF can change the policy to put more upvoted answers on top than just the correct answer. :-)Minded
@VikasGoel: Does this depend on the Eclipse version, or on the compiler/library version, or both?Kimberykimble
@Kimberykimble - only Eclipse versionMinded
M
9

Or go to:

  • C/C++ Build->Discovery Options->GCC C++ Compiler

  • add your flags to the Compiler invocation arguments. like -std=c++11 -m32

  • Clear discovered entrys now: click on Clear

  • rebuild the project

After that ALL symbols will be updated with correct values and the indexer should work as intended

Marcasite answered 16/6, 2013 at 17:17 Comment(4)
This resolved the problem for me. Note that on Eclipse Kepler it is preferences -> C/C++ -> Build -> Settings -> Discovery Tab. It is also mentioned on the eclipse community forums here: eclipse.org/forums/index.php/mv/msg/373462/909018/#msg_909018 . Really unintuitive and hard to find!Buddybuderus
the m32 was just to show that you can add any arguments you like. windows headers for example have significant differences between 32 and 64 bit. So if building a 32bit app on a compiler that uses 64bit mode by default you add -m32 so the indexer is aware of that and parses the correct headersMarcasite
The discovery tab seems to be gone in eclipse mars.Speech
Discovery Options has been deprecated and no longer appears in the menus. Eclipse help documents it here.Lophobranch
B
6

The workaround for me, with a project that uses an external builder, was to define the symbol:

__cplusplus

with the value:

201403

in the project's: Paths and Symbols -> Symbols/GNU C++.

This worked in eclipse Kepler CDT Version: 8.3.0.201402142303.

Braces answered 28/6, 2014 at 21:59 Comment(1)
Worked for me (using a custom Makefile).Footstall
D
3

See this guide:

  1. C/C++ Build->Settings->GCC C++ Compiler->Dialect
  2. Choose "ISO C++11 (-std=c++0x)" in "language standard" Language and dialect
  3. Apply and OK
  4. Rebuild the project and it works:)
Dusen answered 8/4, 2017 at 1:46 Comment(0)
C
2

The follows works in Eclipse C/C++ Oxygen.2 with gcc-5.5.0

Eclipse Properties->C/C++ Build->Settings->GCC C++ Compiler->Dialect->Other dialect flags: -std=c++17

Don't pick up anything in the Language standard dropdown list.

Crean answered 25/6, 2018 at 16:51 Comment(0)
N
0

The following configuration helps me to fix the issue indicated in the original question.

Environment: Eclipse(Oxygen.3a Release (4.7.3a)), Cygwin64. In case you have a different version of Cygwin, you can find similar directories as follows.

Step 1: Make sure you have the following two directories:

   C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include
   C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include\c++

If you don't see the above two directories, please launch your Cygwin setup program and install gcc-core, gcc-g++ and libgcc1.

Step 2: Copy the directory C:\cygwin64\lib\gcc\x86_64-pc-cygwin\7.4.0\include to C:\cygwin64\usr if you don't see above two include directories.

Step 3: Go to Project Property->C/C++ General->Paths and Symbols Make sure you can see the following two paths are listed

   C:\cygwin64\usr\include
   C:\cygwin64\usr\include\c++

Step 4: Property->C/C++ Build/Settings/ Choose Cygwin PE Parser

Step 5: Property->C/C++ Build/Tool Chain Editor Choose Cygwin GCC

Step 6: Property->C/C++ General/Indexer Choose Enable indexer

Step 7: Project->C/C++ Index->Rebuild

Now your eclipse should be able to see the C++11 types.

Nostril answered 28/1, 2019 at 20:48 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.