use c++11 on mac os x mountain lion with eclipse (

2020-07-30 00:51发布

问题:

hey everyone I am just starting to use c++11, which I need for uni, a have a mac and I am familiarise with eclipse (I have both Juno or Kepler with CDT), but as much as I tried I can not run properly any c++11 features in eclipse or compile any code, there is someone that has been in my same position and please help me, seriously I already try all the previous threads about, but for my frustration i am still compiling everything on terminal and editing all in gedit with is not the most confortable way, by the way I have to compile with g++-4.7 as command not g++ meaning that still I have the old OS gnu,please someone just explain me step by step what to do I am terribly frustrated, I beg!!!!

ps. just clarify i install gcc 4.7 with homebrew but the path is different than the original (/usr/local/bin instead of the regular /usr/bin which I believe eclipse use and the reason I can't work with it, thank you for all guys)

回答1:

Well after trying different things and expending tedious time fixing my issue I will answer my own question with the hope someone with my same needs will not experiment such annoying situation.

First as in a lot of forums remark and is well know the gcc compiler provided for the Mac OS is old and obsolete (more than 5 years old is a lot in computing terms), so first step to work with c++11 is to get a new version of the gcc.

There are two options with the packets common managers (homebrew and macports), I have to say that I was that frustrated that i tried both to see if was a problem of the version in the packet manager even thought should be the same, but for my surprise there is a small difference which later I will explain, which bring me to suggest use macport because with macports the eclipse will work as smooth as with the old c++ while with the installation with homebrew the compilation will be the same than the macport but eclipse will complain about the new grammar in the c++11 (eclipse will tell you that the resource couldn't be resolve, even do compile properly ).

The steps for this are assuming you have the command line already:

  1. download the appropriate macports from the official web page(google it)
  2. in terminal type the following commands
    • sudo port selfupdate
    • sudo port upgrade outdated
    • sudo port install -d gcc47
    • port select --list gcc

with this you have gcc and will show you which are the gcc installed in you mac now just missing select as defauld the new gcc, do it with. - sudo port select gcc mp-gcc47

3 having install in my case eclipse kepler create a new C++ project, but instead to left everything standar do the next: - in the wizard window select as toolchain the cross GCC as the toolchain(for example ni the executable Hello World c++ project), put a random name and next , following window press next now here in the window for the selection of the compiler give the path for the new gcc(the default is /opt/local/bin) as prefix leave it empty and press now the finish bottom.

4 Now go to project properties and in c/c++ build select settings and in the tool settings tab go to miscellaneous in cross g++ compiler and in other flags add -std=c++11.

5 by the last go to c/c++ general -> paths and symbols and select the tab symbols and in select the gnu c++ language and press add to type GXX_EXPERIMENTAL_CXX0X as name just that and press ok.

Now just press apply and ok, after that your mac should be running c++11 in eclipse.

Hope works for you as for me see you around guys.

Note probably you will be to configurate the run but it is more simpler than you thing just go to run -> run configurations and double click in c/c++ application now almost everything is generate for you just you have to fill up the first label with the path to the out put of the compiler (I asumme that you already build the project which will generate the executable file ) normally that file is in the debug folder of the project with the same name than the file compiled n does all.

have a good one guys.