score:231

Accepted answer

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

score: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.

score: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.

score: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.

score: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.

score: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.

score: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.

score: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.

score: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

score: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.

score: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.

score: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.

score: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.

score: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

score: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

score: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

score: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.


Related Query

More Query from same tag