5

First of all, I know about the -std=c++11 flag to enable c++11 support and where to place it. I've appended -std=c++11 to Project -> Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags and compiling just works fine. But the indexer doesn't get along, for example if I want to use the emplace function of std::map (c++11), it will not find the emplace function.

#include <map>

int main() {
    std::map<int, int> data;
    data.emplace(5,5);

I've also checked out these related questions:

Update: Now that I've played around it even doesn't recognize the std::map type, although compiling fine and eclipse finding all headers...

  • Compiler Mingw64 GCC 5.2.0
  • Eclipse Mars 4.5
  • CDT 8.7
Tjom
  • 93
  • 1
  • 4
Matze
  • 533
  • 7
  • 16
  • Try this answer: https://stackoverflow.com/questions/17131744/eclipse-cdt-indexer-does-not-know-c11-containers/24628885#24628885 – Galik Sep 18 '15 at 02:16
  • Tried that one, too... also tried under eclipse luna cdt 8.6... seems to be a indexer bug with std::map... will propably report on eclipse forums and link to that one – Matze Sep 18 '15 at 09:36
  • There was an indexer bug but its fixed now. Did you try updating your plugins? `Help -> Check For Updates` from the menu. – Galik Sep 18 '15 at 10:25
  • 1
    Well I was under the impression the fix for the indexer bug was released by now. I fixed it in my eclipse by updating to the current development version (experimental). The *update site* for that is here: Nightly - http://download.eclipse.org/tools/cdt/builds/master/nightly/ use at your own risk :) – Galik Sep 18 '15 at 10:57
  • God thanks! That shit was annoying as hell <3 But i'm surprised by the slightly changed interface... is there a site or something which will cover the changes and features? :) – Matze Sep 18 '15 at 11:28
  • Its such a debilitating bug I assumed they would push it through quickly. Apparently not. IIRC the bug only surfaced with the upgrade to `GCC 5.2`, some change in `GCC` a library header I believe. – Galik Sep 18 '15 at 11:36
  • I think because GCC 5 (.1 or .2 doesn't really matter, 2 is just bugfix) is the first gcc to introduce full feature c++11 – Matze Sep 18 '15 at 11:39

2 Answers2

8

Eclipse Mars does it a bit differently than the previous versions.

Step one gets the indexer error highlighting working - covered in Enable C++11 in Eclipse CDT (Juno/Kepler/Luna) indexer linked above. If you've already done all this, I'll be smurfed if I know what you've run into. Mars has been a bit wonky so far.

  1. Go to Project->properties->C/C++ General->Preprocessor Include Paths.
  2. Click the Providers tab.
  3. Click CDT GCC Built-in Compiler settings MinGW
  4. Click Move Up button on the right.
  5. Under Language Settings Provider Options
    1. Click off Use Global provider shared between projects
    2. Add -std=c++1y to the end of the command line in Command to get compiler specs.

By the way, if anyone knows where the global settings are so I can default this behaviour, please let me know.

Step 2 gets the compiler working

  1. Go to Project->properties->C/C++ Build->Settings.
  2. Go to Tool Settings tab.
  3. Expand GCC C++ Compiler
  4. Click Dialect Pick the C++ Standard you wish to target from the Language Standard drop-down.
Community
  • 1
  • 1
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • 2
    Besides that your step 1 doesn't help in my case, you can do that one under `Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery`... this problem is really nasty, i'll propably try another CDT Version... – Matze Sep 18 '15 at 08:56
  • Sorry I couldn't help, glad you could help me. Thanks! – user4581301 Sep 18 '15 at 14:56
0

Eclipse CDT understands the C++ code in a window by running it through an indexer. This indexer is nothing but an invocation of the GCC C++ compiler with certain compilation options. Sometimes, you might want to change the compiler options used by this indexer.

For example, I recently found that C++11 containers and classes (like future) were not resolved by the indexer and were underlined with red squiggles. This is because the compiler options used by the indexer does not have -std=c++11.

To change the compiler options of the indexer:

  1. Open Preferences and go to C/C++ -> Build -> Settings.
  2. Click the Discovery tab and choose CDT GCC Built-in Compiler Settings.
  3. Modify the command string shown below it as you wish. For example, here I added -std=c++11.
  4. Eclipse CDT will automatically re-index your C++ files after this is saved. However, I found that this did not remove the unresolved items.
  5. I manually re-indexed by right-clicking the project and choosing Index -> Rebuild. This worked!
Mohsen Zahraee
  • 3,309
  • 5
  • 31
  • 45
  • "This indexer is nothing but an invocation of the GCC C++ compiler with certain compilation options." is very misleading. It's true that CDT's Built-in Compiler Settings provider will invoke GCC with certain compilation options - but that's done with an empty file as input, and the only purpose is to discover built-in include paths and #defines. The actual code in the project is processed by CDT's own parser and code analyzer. – HighCommander4 May 09 '17 at 21:31