218

Eclipse 3.7.1 CDT 1.4.1 GCC 4.6.2

This is an example of a piece of C++11 code:

auto text = std::unique_ptr<char[]>(new char[len]);

The Eclipse editor complains about:

Function 'unique_ptr' could not be resolved

The Makefile compilation works fine. How to make Eclipse stop complaining about these sort of errors?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Nick
  • 5,765
  • 5
  • 27
  • 36
  • 12
    At the very least, it should be `std::unique_ptr` – Cubbi Feb 03 '12 at 16:16
  • Not sure that is correct -- char[] is convertible to char* and unique_ptr is a pointer to char, like char* – Nick Feb 03 '12 at 16:24
  • 1
    Wouldn't `unique_ptr` call `delete`, which is wrong since it was created with `new[]`? – Dietrich Epp Feb 03 '12 at 17:44
  • 7
    @Nick: No, he's right. The way you wrote it will cause `delete` to be called, when you *need* `delete[]` called. The `unique_ptr` assumes that it's getting a pointer, which gets deleted with `delete`. `unique_ptr` expects an array, which gets deleted with `delete[]` correctly. – Nicol Bolas Feb 03 '12 at 17:47
  • Related: http://stackoverflow.com/q/8889260/636019, http://stackoverflow.com/q/8763937/636019, http://stackoverflow.com/q/8564544/636019, http://stackoverflow.com/q/8312854/636019 – ildjarn Feb 03 '12 at 19:04
  • @ildjarn: Looks like all are the same question, but I think this one is better written. – Ben Voigt Feb 03 '12 at 20:40
  • 10x guys -- I update the code according to the 1st comment – Nick Feb 06 '12 at 07:44
  • Commenters, please know the syntax. unique_ptr is a new syntax to evoke delete[]. – CashCow Dec 03 '13 at 17:08

17 Answers17

232

I found this article in the Eclipse forum, just followed those steps and it works for me. I am using Eclipse Indigo 20110615-0604 on Windows with a Cygwin setup.

  • Make a new C++ project
  • Default options for everything
  • Once created, right-click the project and go to "Properties"
  • C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++0x (or for newer compiler version -std=c++11 at the end . ... instead of GCC C++ Compiler I have also Cygwin compiler
  • C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and paste __GXX_EXPERIMENTAL_CXX0X__ (ensure to append and prepend two underscores) into "Name" and leave "Value" blank.
  • Hit Apply, do whatever it asks you to do, then hit OK.

There is a description of this in the Eclipse FAQ now as well: Eclipse FAQ/C++11 Features.

Eclipse setting

Eclipse image setting

Mahendra Gunawardena
  • 1,956
  • 5
  • 26
  • 45
Carsten Greiner
  • 2,928
  • 2
  • 16
  • 20
  • I have not tried this, but it makes sense. Eclipse CDT uses gcc's scanner and preprocessor. – EdH Feb 03 '12 at 20:39
  • 2
    Yey, it worked! But, make sure to prepend & append two underscores to GXX_EXPERIMENTAL_CXX0X -- I will accept this in the meantime – Nick Feb 06 '12 at 07:49
  • 5
    Did this remove spurious editor errors? I have no problem with compiling, and new std types are recognised, but I can't get rid of editor syntax errors for range based for loops and rvalue references `&&`. – juanchopanza May 03 '12 at 13:09
  • Yeah, when I followed the above settings, then the "red wiggles" were gone, too. – Carsten Greiner May 03 '12 at 20:20
  • 8
    The natural follow-up question now becomes: can we optimize our workflow by saving these specific C++ Project Settings into a new Eclipse Project template say "C++11 Project"? – Nordlöw May 21 '12 at 21:34
  • Does not work for me. Does not accept the c++11 version of `vector.insert()` – ManuelSchneid3r Nov 19 '12 at 16:21
  • 39
    Note: for anyone looking for the answer for Juno, this _does not work_. – Christopher Dec 31 '12 at 16:37
  • 2
    can compile and run successfully, but show some error:Methord could not be resolved. – user501836 Jan 22 '13 at 02:18
  • 4
    For kepler/juno, the solution is found in [this answer](http://stackoverflow.com/a/13635080/1149664). It's posted in the edit to Johan Lundberg's reply below, but I note it here as well, to make the accepted answer more complete. – Inusable Lumière Nov 27 '13 at 15:45
  • @Christopher works for me, using Juno, and MinGW with gcc/g++ version 4.7 – Shivan Dragon Dec 13 '13 at 12:40
  • @Christopher: http://stackoverflow.com/questions/10803685/eclipse-cdt-symbol-cout-could-not-be-resolved the issue for me was that I was missing the include: `/usr/include/c++/4.6/x86_64-linux-gnu` – Alexander Oh Feb 09 '14 at 19:08
  • Also you can change __cplusplus to 201103L – Gelldur Mar 27 '14 at 11:21
  • For anybody searching for answer for Luna. This does not work! – Trismegistos Jul 03 '14 at 18:53
  • As mentioned above for Kepler/Juno, the following link is confirmed to fix this on Luna: http://stackoverflow.com/questions/13635079/enable-c11-in-eclipse-cdt-juno-kepler-indexer/13635080#13635080 – Steve Aug 08 '14 at 02:19
  • 1
    the luna fix link does not suffice on it's own. you have to combine it with the __GXX_EXPERIMENTAL_CXX0X__option from this answer here. at least only that solved my problem, resolving std:stoi :/ – ViGi Mar 15 '15 at 19:58
  • I am unable to find c/c++ Build option.In my eclipse in project properties its only showing c/c++ General.What should i do??? – Sagar Patel Oct 23 '15 at 05:55
  • You have to ensure that when your create the project in eclipse it is a C++ project. – Carsten Greiner Oct 30 '15 at 09:22
  • 1
    Note, that [the "Tool Setting" Tab is only visible when "Generate Makefiles automatically" is enabled](http://stackoverflow.com/a/24412146/1557062). You need to temporarily enable said option in order to set the dialect to C++11. – sigy Dec 05 '16 at 11:20
  • For Eclipse 2018-12, only this answer worked for me: https://stackoverflow.com/a/35880100/1152819 – David Steinhauer Jan 08 '19 at 19:55
153

Instruction For Eclipse CDT 4.4 Luna and 4.5 Mars

First, before creating project, configure Eclipse syntax parser:

Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build-in Compiler Settings

in the text box entitled Command to get compiler specs append -std=c++11

Now you can create project, configuration depends on what kind of project you created:

For project created as: File -> New -> Project -> C/C++ -> C++ Project

Right click on created project and open

Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Dialect

Put -std=c++11 into text box entitled other dialect flags or select ISO C++11 from the Language standard drop down.

For CMake project

Generate eclipse project files (inside your project)

mkdir build
cd build
cmake -G"Eclipse CDT4 - Unix Makefiles" -D CMAKE_BUILD_TYPE=Debug ..

Then import generated directory to eclipse as standard eclipse project. Right click project and open

Properties -> C/C++ General -> Preprocessor Include Paths, Marcos etc. -> Providers

enable CDT GCC Build-in Compiler Settings and move it higher than Contributed PathEntry Containers (This is important)

Last Common Step

recompile, regenerate Project ->C/C++ Index and restart Eclipse.

Trismegistos
  • 3,821
  • 2
  • 24
  • 41
112

Update 2016:

As of gcc 6 (changes), the default C++ dialect is C++14. That means that unless you explicitly need a newer or older dialect than than, you don't need to do anything with eclipse anymore.

For Luna and Mars

This community wiki section incorporates the answer by Trismegistos;

1. Before creating project, configure Eclipse syntax parser:

Window -> Preferences -> C/C++ -> Build -> Settings -> Discovery -> CDT GCC Build-in Compiler Settings

in the text box entitled Command to get compiler specs append -std=c++14 2. Create project, configuration depends on what kind of project you created:

For project created as: File -> New -> Project -> C/C++ -> C++ Project

Right click on created project and open

Properties -> C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Dialect

Put -std=c++14 into text box entitled other dialect flags or select ISO C++11 from the Language standard drop down.

There's now a new way to solve this without the GXX_EXPERIMENTAL hack.

For most recent versions: (Currently Juno and Kepler Luna):

Under newer versions of Juno the settings are located at Project properties -> C/C++ General -> Preprocessor Include Paths, Macros etc. -> tab Providers -> CDT GCC Builtin Compiler Settings ().

Older versions 2012/2013:

  1. Under C/C++ Build (at project settings), find the Preprocessor Include Path and go to the Providers Tab. Deselect all except CDT GCC Builtin Compiler Settings. Then untag Share settings entries … . Add the option -std=c++11 to the text box called Command to get compiler specs.

  2. Go to paths and symbols. Under Symbols, click restore defaults, and then apply.


Notes:

Eclipse is picky about hitting apply, you need to do it every time you leave a settings tab.

[Self-promotion]: I wrote my own more detailed instructions based on the above. http://scrupulousabstractions.tumblr.com/post/36441490955/eclipse-mingw-builds

Thanks to the user Nobody at https://stackoverflow.com/a/13635080/1149664

Community
  • 1
  • 1
Johan Lundberg
  • 26,184
  • 12
  • 71
  • 97
  • 3
    Thank you but it didn't help me to solve c++11 references. Program compiles correctly, but eclipse cannot resolve them. When I check "array", `#ifndef __GXX_EXPERIMENTAL_CXX0X__` returns true and code below it is not parsed. When I add `__GXX_EXPERIMENTAL_CXX0X__` to project symbols, array gets resolved but my project's references gets messed up. What might be the problem here? – Halil Dec 20 '12 at 16:10
  • Not sure what you mean by check array. Did you try to follow the instructions on my blog? – Johan Lundberg Dec 20 '12 at 16:22
  • Yes I did. In fact, I've just tried it with fresh Eclipse project, it worked. However, with my old project, first it had no effect. When I closed it and re-opened it, std::array is resolved, but then my project references not parsed, as if when I add `__GXX_EXPERIMENTAL_CXX0X__` manually. Now I have like 200 unresolved project references. Any thoughts how can I get rid of this? – Halil Dec 20 '12 at 16:48
  • 1
    I think it is a bug. I re-produced it like this: Open new project. Enable c++11 features. Add a random class with a public variable. Create vector of this random class. Get the iterator. Try to access public variable. Either my workspace is corrupted or there is a bug in Eclipse that cannot parse this. – Halil Dec 20 '12 at 17:00
  • 1
    @HalilKaskavalci I found this same bug. If I set the editor for c++11, iterators can't resolve. If I don't, std::unique_ptr can't resolve. Really annoying, since I use both. – Kian Dec 20 '12 at 22:24
  • 1
    @Kian I reported the bug. https://bugs.eclipse.org/bugs/show_bug.cgi?id=397027 . It is quite annoying and I started to use boost libraries, they don't produce the error :) – Halil Dec 20 '12 at 23:19
  • Just tried instructions from your blog post, and `array` is still unresolved. – Jeff Dec 22 '12 at 19:55
  • @Jeff. strange. Is this resolved: #include int blah(){ std::mutex a; std::lock_guard locker(a); }. Have a look at my instructions again, I added how to use the nightly build of CDT. – Johan Lundberg Dec 23 '12 at 07:46
  • Nope, doesn't work with Indigo / MINGW (made it worse actually since now it doesn't find `#include `... BTW, don't forget in your blog that `-std=gnu++11` is only supported from gcc 4.7, you have to use `-std=gnu++0x` in 4.6. – RedGlyph Mar 22 '13 at 09:32
  • Thanks.. in my case I didn't need to Deselect all except CDT GCC Built-in Compiler Settings. – polerto Jul 08 '13 at 21:30
  • It would have been nice to note that the restore defaults applies to ALL settings of the project cleaning the includes and libraries of the project not just the symbols tab. Now I have to manually add them. – Paulo Neves Jul 08 '14 at 18:14
  • 1
    works for me! Thank you! (did it by your reference) I'va added -std=c++11 to providers and restore defaults in symbols. I think restore default in symbols saves me. Now unique_ptr is resolving. – Denis Zaikin Oct 16 '14 at 09:22
  • Works on **Luna** (GNU/Linux). **Restore Defaults** is important. – Vladislav Ivanishin Mar 05 '15 at 11:07
  • @VladislavIvanishin, could you add the missing steps if any to the answer? – Johan Lundberg Mar 06 '15 at 19:51
  • 1
    @JohanLundberg, there were no missing steps for me. As a matter of fact there is even an extra step in the detailed instruction (for the purposes the OP has stated). So basically it was -std=c++11 flag and restore defaults. – Vladislav Ivanishin Mar 07 '15 at 20:34
  • On **Kepler**, Restore Defaults wasn't helpful and it would have thrown away some customizations. Instead, add -std=c++11 to the builtin compiler options as described above, apply the changes, then Project Menu > **C/C++ Index > Rebuild** and wait until it completes. – unpoetical Mar 21 '16 at 20:33
  • @Johan Lundberg can you take a look at my question - I feel like this is the same problem but I fail when attempting to apply the solution. [link](http://stackoverflow.com/questions/40658561/digit-separators-c14-in-eclipse-compiles-but-marked-as-syntax-error) – Johannes Nov 17 '16 at 16:55
20

For the latest (Juno) eclipse cdt the following worked for me, no need to declare __GXX_EXPERIMENTAL_CXX0X__ on myself. This works for the the CDT indexer and as parameter for the compiler:

"your project name" -> right click -> properties:

C/C++ General -> Preprocessor Include Paths, Macros etc. -> switch to the tab named "Providers":

  • for "Configuration" select "Release" (and afterwards "debug")

  • switch off all providers and just select "CDT GCC Built-in Compiler Settings"

  • uncheck "Share setting entries between projects (global provider)"

  • in the "Command to get compiler specs:" add "-std=c++11" without the quotes (may work with quotes too)

  • hit apply and close the options

  • rebuild the index

Now all the c++11 related stuff should be resolved correctly by the indexer.

win7 x64, latest official eclipse with cdt mingw-w64 gcc 4.7.2 from the mingwbuilds project on sourceforge

Andreas
  • 380
  • 3
  • 6
  • still getting same erroneous editor warnings, as in Type 'std::thread' could not be resolved even though it compiles and executes OK – Scott Stensland May 31 '13 at 11:27
  • 2
    u need to compile once with the new settings, so the parser will "learn" that the std=c++11 flag is set – Andreas Jun 11 '13 at 09:16
  • depending on the compiler version it might be necessary to add -std=c++0x instead of -std=c++11 (e.g. debian wheezy) – xmoex Aug 19 '14 at 15:57
15

I had the same problem on my Eclipse Juno. These steps solved the problem :

  • Go to Project -> Properties -> C/C++ General -> Path and Symbols -> Tab [Symbols].
  • Add the symbol : __cplusplus with the value 201103L
Jerome
  • 1,225
  • 2
  • 12
  • 23
  • 2
    This should be accepted answer since it works also for Makefile projects! – omikron Dec 12 '14 at 10:02
  • @Jerk31 this is not working for Eclipse Juno running on windows(for me), I still see those complained un-necessary errors, despite the binary is working fine. Please help me!!! – overexchange Jan 06 '15 at 11:37
  • I'm really sorry I can't help you on Windows I don't have the opportunity to try to execute any C++ project on this OS. I wish you the best and good luck ! – Jerome Jan 07 '15 at 12:32
  • I would avoid this solution, as it's overwriting what the compiler is defining. That said I'm about to go this route since I can't get -std option to work on Eclipse 2021 on Ubuntu – David Bradley Jan 29 '22 at 22:25
14

For Eclipse CDT Kepler what worked for me to get rid of std::thread unresolved symbol is:

  1. Go to Preferences->C/C++->Build->Settings

  2. Select the Discovery tab

  3. Select CDT GCC Built-in Compiler Settings [Shared]

  4. Add the -std=c++11 to the "Command to get the compiler specs:" field such as:

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

  1. Ok and Rebuild Index for the project.

Adding -std=c++11 to project Properties/C/C++ Build->Settings->Tool Settings->GCC C++ Compiler->Miscellaneous->Other Flags wasn't enough for Kepler, however it was enough for older versions such as Helios.

YSelf
  • 2,646
  • 1
  • 14
  • 19
user3348915
  • 141
  • 1
  • 2
  • For Eclipse Version: 2019-09 R. This solution worked for me, however, I've spent a lot of time before that. The problem was in Builder Settings: Project -> Properties -> C/C++ Build: in tab 'Builder Settings' choose 'Internal builder' for 'Builder type'. – grekhss Dec 04 '19 at 13:25
5

I can't yet comment so am writing my own answer:

It's related to __GXX_EXPERIMENTAL_CXX0X__ and it's valid for Eclipse Juno and CDT 8.x.

Some parts of this answer are already covered in other answers but I want it to be coherent.

To make it possible to build using stdc++11, one have to add specific flag for compiler. You can do that via project properties. To modify project properties RMB andProject properties or ALT + ENTER. Then C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++11 at the end of line, for GCC it will look something like: -c -fmessage-length=0 -std=c++11. By adding -stdc++11 flag compiler (GCC) will declare __GXX_EXPERIMENTAL_CXX0X__ by itself.

At this point you can build project using all the goodness of C++11.

The problem is that Eclipse has it's own parser to check for errors - that's why you're still getting all the nasty errors in Eclipse editor, while at the same time you can build and run project without any. There is a way to solve this problem by explicitly declaring __GXX_EXPERIMENTAL_CXX0X__ flag for the project, one can do that (just like Carsten Greiner said): C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and past __GXX_EXPERIMENTAL_CXX0X__ (ensure to append and prepend two underscores) into "Name" and leave "Value" blank. And now is the extra part I wanted to cover in comment to the first answer, go to: C/C++ General -> Preprocessor Include Path Macros etc. -> Providers, and Select CDT Managed Build Setting Entries then click APPLY and go back to Entries tab, under GNU C++ there should be now CDT Managed Build Setting Entries check if inside there is defined __GXX_EXPERIMENTAL_CXX0X__ if it is -> APPLY and rebuild index you should be fine at this point.

rav
  • 3,579
  • 1
  • 18
  • 18
3

I had several issues too (Ubuntu 13.04 64-bit, g++-4.8, eclipse Juno 3.8.1, CDT 6.0.0). A lot of things are mentioned above, sorry to repeat those, but additionally I had problems utilizing

std::thread

as part of c++11 (adding -pthread for the linker solves that issue). Anyway, finally these settings worked fine:

Project -> Properties -> C/C++ Build -> Settings -> Miscellaneous. Add the

-std=c++11

flag for the GCC and G++ compilers. Click Apply.

For the linker, same window, Miscellaneous, Linker flags, added the

-pthread

flag. Shared library settings, Shared object name, add the

-Wl,--no-as-needed

flag too. Click Apply.

C/C++ General -> Paths and symbols -> Symbols TAB, GNU C++ selected, Add the

__GXX_EXPERIMENTAL_CXX0X__

(no value)

flag. Click Apply.

C/C++ General -> Preprocessor Include paths.. -> Providers tab : check

CDT GCC built-in Compiler Settings

and for "Command to get compiler specs", add the

-std=c++11

flag. Uncheck Share. Click Apply.

CDT Managages Build Setting Entries, check this too. Uncheck the two others. Click Apply.

Going back to the Entries tab, GNU C++ CDT Managages Build Setting Entries, you should now see your added

__GXX_EXPERIMENTAL_CXX0X__

entry.

That's it. When coding, typing

std::

can now auto-complete the thread class for instance, builds should work fine and there should be no

std::system_error'what(): Enable multithreading to use std::thread: Operation not permitted

at runtime.

Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129
Ola Aronsson
  • 411
  • 4
  • 7
  • It was the `Project -> Properties -> C/C++ Build -> Settings -> Miscellaneous` step that worked for me. Thanks a bunch :D – Jake88 Feb 14 '14 at 16:19
2

I don't know if it is only me, the highest ranked solution doesn't work for me, my eclipse version is just normal eclipse platform installed by using sudo apt-get install eclipse in Ubuntu But I found a solution which adopts method together from both the highest ranked solution and the second, what I did to make it work is described as below (Note that the other steps like creating a C++ project etc. is ignored for simplicity)

Once you have created the C++ project

(1) C/C++ General -> Paths and Symbols -> Symbols -> GNU C++. Click "Add..." and paste GXX_EXPERIMENTAL_CXX0X (ensure to append and prepend two underscores) into "Name" and leave "Value" blank.

(2) Under C/C++ Build (at project settings), find the Preprocessor Include Path and go to the Providers Tab. Deselect all except CDT GCC Builtin Compiler Settings. Then untag Share settings entries … . Add the option -std=c++11 to the text box called Command to get compiler specs

After performed above 2 and 2 only steps, it works, the eclipse is able to resolve the unique_ptr, I don't know why this solution works, hope that it can help people.

doody1986
  • 81
  • 3
  • This also worked for me (eclipse neon). At first I didn't deselect the other providers, which still caused problems, but deselecting all other providers than "CDT GCC Built-in Compiler Settings" and "CDT User Settings" worked. Thanks! – zpon Sep 07 '16 at 13:11
2

Eclipse C/C++ does not recognize the symbol std::unique_ptr even though you have included the C++11 memory header in your file.

Assuming you are using the GNU C++ compiler, this is what I did to fix:

Project -> Properties -> C/C++ General -> Preprocessor Include Paths -> GNU C++ -> CDT User Setting Entries

  1. Click on the "Add..." button

  2. Select "Preprocessor Macro" from the dropdown menu

    Name: __cplusplus     Value:  201103L
    
  3. Hit Apply, and then OK to go back to your project

  4. Then rebuild you C++ index: Projects -> C/C++ Index -> Rebuild

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Rubens Gomes
  • 482
  • 5
  • 10
2

For me on Eclipse Neon I followed Trismegistos answer here above , YET I also added an additional step:

  • Go to project --> Properties --> C++ General --> Preprocessor Include paths,Macros etc. --> Providers --> CDT Cross GCC Built-in Compiler Settings, append the flag "-std=c++11"

Hit apply and OK.

Cheers,

Guy.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
0
  • right-click the project and go to "Properties"
  • C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -lm at the end of other flags text box and OK.
0

Neither the hack nor the cleaner version work for Indigo. The hack is ignored, and the required configuration options are missing. For no apparent reason, build started working after not working and not providing any useful reason why. At least from the command line, I get reproducible results.

Jerry Miller
  • 921
  • 1
  • 8
  • 11
0

To get support for C++14 in Eclipse Luna, you could do these steps:

  • In C++ General -> Preprocessor Include -> Providers -> CDT Cross GCC Built-in Compiler Settings, add "-std=c++14"
  • In C++ Build -> Settings -> Cross G++ Compiler -> Miscellaneous, add "-std=c++14"

Reindex your project and eventually restart Eclipse. It should work as expected.

Jerome
  • 1,225
  • 2
  • 12
  • 23
0

I solved it this way on a Mac. I used Homebrew to install the latest version of gcc/g++. They land in /usr/local/bin with includes in /usr/local/include.

I CD'd into /usr/local/bin and made a symlink from g++@7whatever to just g++ cause that @ bit is annoying.

Then I went to MyProject -> Properties -> C/C++ Build -> Settings -> GCC C++ Compiler and changed the command from "g++" to "/usr/local/bin/g++". If you decide not to make the symbolic link, you can be more specific.

Do the same thing for the linker.

Apply and Apply and Close. Let it rebuild the index. For a while, it showed a daunting number of errors, but I think that was while building indexes. While I was figuring out the errors, they all disappeared without further action.


I think without verifying that you could also go into Eclipse -> Properties -> C/C++ -> Core Build Toolchains and edit those with different paths, but I'm not sure what that will do.

Joseph Larson
  • 8,530
  • 1
  • 19
  • 36
0

I had a similar problem using Eclipse C++ 2019-03 for a mixed C and C++ project that used std::optional and std::swap. What worked for me was this.

In the project Properties->C/C++ Build->Settings->Tool Settings->Cross G++ Compiler, remove -std=gnu++17 from Miscellaneous and put it in Dialect->Other Dialect Flags instead.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
dc42
  • 314
  • 3
  • 6
0

When using a cross compiler, I often get advanced custom build systems meticulously crafted by colleagues. I use "Makefile Project with Existing code" so most of the other answers are not applicable.

At the start of the project, I have to specify that I'm using a cross compiler in the wizard for "Makefile Project with Existing Code". The annoying thing is that in the last 10 or so years, the cross compiler button on that wizard doesn't prompt for where the cross compiler is. So in a step that fixes the C++ problem and the cross compiler problem, I have to go to the providers tab as mentioned by answers like @ravwojdyla above, but the provider I have to select is the cross-compiler provider. Then in the command box I put the full path to the compiler and I add -std=gnu++11 for the C++ standard I want to have support for. This works out as well as can be expected.

You can do this to an existing project. The only thing you might need to do is rerun the indexer.

I have never had to add the experimental flag or override __cplusplus's definition. The only thing is, if I have a substantial amount of modern C code, I have nowhere to put the C-specific standard option.

And for when things are going really poorly, getting a parser log, using that command in the Indexer submenu, can be very informative.

cardiff space man
  • 1,442
  • 14
  • 31