Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » C++11 standard library indexing fails, __cplusplus recognized with wrong value(C++11 standard library indexing fails)
icon5.gif  C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1067392] Mon, 08 July 2013 09:49 Go to next message
Michael Hofmann is currently offline Michael Hofmann
Messages: 9
Registered: December 2012
Junior Member
When using CDT 8.2 in Eclipse (tried Juno as well as Kepler), I cannot get the indexer to recognise code that uses C++11 standard library features, i.e. classes such as std::array, std::unique_ptr, std::shared_ptr, etc. do not get recognised and are therefore underlined with red squiggles. Same for any class that uses one of these new elements, with the effect that the majority of my code gets underlined in red. Sad

The main culprit *seems to be* that the indexer get a wrong value for the __cplusplus macro; it is 199711L instead of the required 201103L. See the attached picture of an excerpt of the GCC <memory> header.
However, I do not know how to tell Eclipse/CDT how to set the correct value for the __cplusplus macro.
I have already done the following:
- The Discovery, Builtin compiler options include '-std=c++11'.
- The compiler options include '-std=c++11'.
- The preprocessor macro __GXX_EXPERIMENTAL_CXX0X__ is set.
See also the other attached pictures.
This pretty much corresponds to the advice given in the CDT FAQ.
The allocated console w.r.t. to the discovery options clearly states the *correct* value for __cplusplus. The log output contains:

"**** Running scanner discovery: CDT GCC Builtin Compiler Settings ****
g++ -E -P -v -std=c++11 -dD /Users/michael/workspace/.metadata/.pluginsorg.eclipse.cdt.managedbuilder.core/spec.C
[...]
Configured with: ../gcc-4.8.1/configure [...] --libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48 [...]
[...]
#define __cplusplus 201103L <------------ this is correct
gcc version 4.8.1 (MacPorts gcc48 4.8.1_1)
[...]"

I have already tried to rebuild the entire index several times, to no avail.
How can I make the indexer to see __cplusplus as 201103L, such that my code is indexed correctly?
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1067789 is a reply to message #1067392] Wed, 10 July 2013 11:06 Go to previous messageGo to next message
Klaus Mr is currently offline Klaus Mr
Messages: 109
Registered: November 2011
Senior Member
Hello Michael,

check the values under "Preprocessor Include Paths, Macros etc.". There you should find the values CDT has parsed from the scanner discovery output.

index.php/fa/15559/0/


regards,
Klaus
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1067801 is a reply to message #1067789] Wed, 10 July 2013 11:59 Go to previous messageGo to next message
Michael Hofmann is currently offline Michael Hofmann
Messages: 9
Registered: December 2012
Junior Member
Well, it is saying "__cplusplus=201103L" there, and also if I view the console output w.r.t. discovery options (which is probably the same thing).
That's why it's extremely puzzling to see the indexer preprocess the source code wrongly, as shown in the _code_memory.png image attached above.

What can I do to fix this? I have squiggles all over my source code of several large projects, and it doesn't look pretty.

(Side note: I have to say that setting up Eclipse/CDT for proper C++ support has always been quite a pain so far... this should work out of the box or be more intuitive.)
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1067825 is a reply to message #1067801] Wed, 10 July 2013 13:39 Go to previous messageGo to next message
Klaus Mr is currently offline Klaus Mr
Messages: 109
Registered: November 2011
Senior Member
I only can give further hint:

What happens, when you press F3 when the cursor is on __cplusplus?

After adding -std=c++11 - did you rebuild the index?

Do you use the same compiler for build and for scanner discovery?

Check the build output log, is there any setting changing __cplusplus?

Also you could try this:

Make an new Workspace, create the integrated Hello-World example, add -std=c++11 to both settings and then rebuild the index, add some code with __cplusplus. What happens?


regards,
Klaus
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1067976 is a reply to message #1067825] Thu, 11 July 2013 09:56 Go to previous messageGo to next message
Michael Hofmann is currently offline Michael Hofmann
Messages: 9
Registered: December 2012
Junior Member
Thanks for the pointer about setting up a new workspace! I seem to have fixed most of the issues that I've had with the indexing.

This is going to be quite a rant, since I find the user experience in setting this up unacceptable. In case any developers are reading this, please pay good attention...

Since I had to set up a new workspace, I had to re-do all the steps to just get Eclipse/CDT to recognise my compiler correctly. It is painful, and so far I've lost half a day to stupid trial-and-error (not the first time this has happened with Eclipse/CDT):


  • I'm using GCC 4.8.1 on a Mac via MacPorts. Without manually changing the PATH variable in the global environment settings it will only recognise the Apple GCC compiler (an ancient 4.2.1, present by default on the system). And it's more difficult than just changing it to "/opt/local/bin:$PATH" - for some reason, it won't recognise that and all paths have to be spelled out explicitly(!). That's not very intuitive.

  • Even then, the indexer will *mostly* see the GCC 4.2.1 include files for the standard library. I'm saying mostly, because it will pick up the correct path for files that don't exist in the 4.2.1 include location yet (C++11-only stuff such as type_traits). Needless to say, the indexer doesn't like that.

    In order to fix this I have to add the GCC 4.8 standard library directories as the topmost include paths to *all* my projects, as follows:
    1) /opt/local/include/gcc48/c++/x86_64-apple-darwin12/
    2) /opt/local/include/gcc48/c++/

    This has to be done using both these paths in exactly this order, otherwise indexing will fail in strange ways. (For example: If I remove the first include directory, following <type_traits> gets me to the correct include, but the included <bits/c++config.h> inside type_traits will be from GCC 4.2.1. Good luck figuring stuff like that out.)

    It's weird that this mess happens in the first place, since the scanner discovery output *seems* ok, with all the right directories. See part of the log:
    14:57:53 **** Running scanner discovery: CDT GCC Built-in Compiler Settings ****
    g++ -E -P -v -std=c++11 -dD /Users/michael/workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C
    #define __cplusplus 201103L
    (...)
    Configured with: ../gcc-4.8.1/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc48 --includedir=/opt/local/include/gcc48 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.8 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.8 --with-gxx-include-dir=/opt/local/include/gcc48/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --disable-cloog-version-check --enable-stage1-checking --disable-multilib --enable-lto --enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --with-pkgversion='MacPorts gcc48 4.8.1_1'


  • Of course I also have to add "-std=c++11" in obscure places. Who in his right mind would get the idea to look under the hidden 'Discovery' tab to add this to the built-in compiler options? The fact that this is mentioned in the FAQ doesn't make it any better.

  • With all this set up, the indexer *still* cannot deal with all my code. I'm pretty sure all issues related to include directories are fixed, and what remains are actual indexer bugs. For example, it chokes on this simple case:

    #include <type_traits>
    constexpr bool BAR() { return true; }
    struct Foo
    {
    void foo(std::enable_if<true>::type* = nullptr) {} // indexer is fine with this
    void bar(std::enable_if<BAR()>::type* = nullptr) {} // indexer has issues with that
    };


Sad

Can't this all be a bit more intuitive? Can't there be, say, some setup procedure that just works(TM)?
Something along the lines of "We found the following compilers on your system: 1) ... 2) ... 3) ... . Which one would you like to use?" And then "Do you want to enable C++ 11 features/indexing in your projects? yes/no".
The steps anyone has to go through at the moment to set this up correctly are beyond acceptable. I don't even want to know what the hell will happen when I want to switch to a Clang toolchain at some point...

Michael
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1067982 is a reply to message #1067976] Thu, 11 July 2013 10:22 Go to previous messageGo to next message
Michael Hofmann is currently offline Michael Hofmann
Messages: 9
Registered: December 2012
Junior Member
Nope. Not all solved. Suddenly, in another project, the mouse-over over the __cplusplus definition tells me that it's recognized as '1'. No idea why, and of course the indexer doesn't like that. Every setting looks ok, though, and it's telling me everywhere else (i.e. in the properties) that the macro is 201103L.
Why does this have to be such a bloody mess?
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1068001 is a reply to message #1067976] Thu, 11 July 2013 11:37 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
You should change the PATH environment variable in Windows->Preferences->C/C++->Build->Environment.
- click on "Select ..."
- then select PATH and click OK
- then click "Edit.."
- you should insert the path to g++ at the beginning (I guess it is /opt/local/bin)

You can overwrite these global settings per project (if you like).

In Windows->Preferences->C/C++->Build->Settings open the "Discovery" tab
- select GCC-Builtin Compiler Settings (I think in your case it will be called GCC Mac or something linke this. I am not sure.)
- change the command line
${COMMAND} -E -P -v -dD "${INPUTS}"

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

That's it. (Don't forget to select Mac GCC as your toolchain)

It should *not* be necessary to add any include paths manually. The automatic discovery will (should) do it.


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1068004 is a reply to message #1068001] Thu, 11 July 2013 11:45 Go to previous messageGo to next message
Michael Hofmann is currently offline Michael Hofmann
Messages: 9
Registered: December 2012
Junior Member
Well, I have done those two things already; see my previous posts where I describe this in detail.

For now, I have added '-D__cplusplus=201103L' to the built-in compiler discovery options. It's brute-force, but it does seem to help at least with the __cplusplus definition, which set itself to '1' for no reason (in one project).

I agree that I should not have to manually add include paths. See the part of the scanner discovery console log that I posted above. That should be sufficient for the indexer to "get it".
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1068097 is a reply to message #1068004] Fri, 12 July 2013 03:02 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
For now, I have added '-D__cplusplus=201103L' to the built-in compiler discovery options.

How did you do this? The built-in compiler discovery symbols are read-only.

I have noticed that you set the preprocessor macro __GXX_EXPERIMENTAL_CXX0X__, in addition. Perhaps there is a conflict when you set __GXX_EXPERIMENTAL_CXX0X__ and -std=c++11.



Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1068142 is a reply to message #1067982] Fri, 12 July 2013 08:02 Go to previous messageGo to next message
Klaus Mr is currently offline Klaus Mr
Messages: 109
Registered: November 2011
Senior Member
Hello Michael,

Quote:
I'm using GCC 4.8.1 on a Mac via MacPorts. Without manually changing the PATH variable in the global environment settings it will only recognise the Apple GCC compiler (an ancient 4.2.1, present by default on the system).


Quote:
Suddenly, in another project, the mouse-over over the __cplusplus definition tells me that it's recognized as '1'.


I only could guess, but maybe for unknown reasons CDT finds the old Compiler 4.2.1. And older compilers (up to 4.7) sets __cplusplus = 1.

I found this GCC Bugzilla entry about this issue:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=1773


I'm not a Mac-User, but using Windows I always use a Batch-File to start Eclipse. I do this because than I simply can add the Path to the Compiler I want. For example the batch may look like this:

PATH=C:\MinGW32\bin;%PATH%
start eclipse.exe

This adds the path to my GCC-Compiler (C:\MinGW32\bin;) in front of the other search paths and therefore I'm sure that Eclipse/CDT finds this compiler version (and not a other older version which also could be in the search PATH).
The other advantage is, that I must not add the paths to the GCC-Headers manually within the CDT-Settings.

Hope this helps you to find out the problem...

regards,
klaus
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1068148 is a reply to message #1067976] Fri, 12 July 2013 08:23 Go to previous messageGo to next message
Klaus Mr is currently offline Klaus Mr
Messages: 109
Registered: November 2011
Senior Member
i forgot:

Quote:
With all this set up, the indexer *still* cannot deal with all my code.


Last year i made a brief list of bugzilla-entrys about missing C++ features in CDT/Indexer.
It's here:
http://www.eclipse.org/forums/index.php/t/376496/


So do not expect, that the Indexer (and CODAN also i think) is fully able to handle C++11...

regards,
klaus
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1073664 is a reply to message #1068142] Thu, 25 July 2013 04:57 Go to previous messageGo to next message
Axel Mueller is currently offline Axel Mueller
Messages: 1949
Registered: July 2009
Senior Member
I guess you run into the following bug:
Built-In Settings Provider ignores compiler command from build Settings
https://bugs.eclipse.org/bugs/show_bug.cgi?id=404912
Scanner discovery uses the old gcc installation.
In Windows->Preferences->C/C++->Build->Settings open the "Discovery" tab. Here you should change ${COMMAND} to /opt/local/bin/gcc (or whereever you have installed GCC 4.8.1).
(btw, use g++ für C++)


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1240601 is a reply to message #1073664] Thu, 06 February 2014 15:46 Go to previous messageGo to next message
Karl Kaess is currently offline Karl Kaess
Messages: 1
Registered: February 2014
Junior Member
I found that you can redefine __cplusplus by adding it to your CDT User Setting Entries (under C/C++ General->Preprocessor Includes...) and then rebuild your c/c++ index. It's a workaround, but it works the first time, every time.

Of course, this problem may be resolved in the above posts.
Re: C++11 standard library indexing fails, __cplusplus recognized with wrong value [message #1270792 is a reply to message #1067392] Thu, 13 March 2014 09:52 Go to previous message
Thread Feuerstein is currently offline Thread Feuerstein
Messages: 1
Registered: March 2014
Junior Member
Stumbled across the same problem. I've added "-std=c++11" to the discover command as described by Axel Mueller in post "Thu, 11 July 2013 11:37", but doesn't fix the problem.

I subsequently switched to "Project Properties->C/C++ General->Preprocessor Include Paths..->Providers tab. There, I had to enable "CDT GCC Build-in Compiler Settings [ Shared ]" (was disabled) and moved it to to top of this list. After clicking "Apply" _cplusplus has been updated and the indexer accepted most parts. Rebuilding the index fixed the remaining parts. It seems to work at the moment.

Details: Eclipse Kepler 4.3.2, CDT 8.3, CMake[2.8.12, CDT4 Makefile] Out-Of-Source Project, Manjaro 0.8.9, Hotspot JVM 7.0_51

Previous Topic:Setting preferences (CDT Environment) using plugin_customization.ini
Next Topic:namespace problem : could not been resolved
Goto Forum:
  


Current Time: Wed Aug 20 06:47:37 EDT 2014

Powered by FUDForum. Page generated in 0.02533 seconds