Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse will not use gcc 4.7 on Mac

Tags:

gcc

I installed gcc47 using macports. I used select to make gcc47 my active compiler. When I type gcc --version in terminal I get this: gcc (MacPorts gcc47 4.7.2_2) 4.7.2 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

When I try to compile c++ code in Eclipse I get: Invoking: GCC C++ Compiler g++ -D__GXX_EXPERIMENTAL_CXX0X__ -I/Users/XXXX/QtSDK/Madde/sysroots/harmattan_sysroot_10.2011.34-1_slim/usr -O0 -g3 -Wall -c -fmessage-length=0 -std=c++0x -MMD -MP -MF"XXXX_Process.d" -MT"XXXX_Process.d" -o "XXXX_Process.o" "../XXXX_Process.cpp" cc1plus: error: unrecognized command line option "-std=c++0x" make: * [XXXX_Process.o] Error 1

I am not sure what I am not doing to make this work. I need a more up to date compiler for programs I am writing in my for school. Thanks in advance for your help.

like image 651
user1742854 Avatar asked Oct 13 '12 05:10

user1742854


Video Answer


2 Answers

The problem is the order of discovery on the path for eclipse is different then the order in your terminal. I had tried symlinking as suggest above and that still didn't fix my problem, but this did!

After much searching around and trying other things, I was able to manually set the path to my compilers and linkers in Project -> Properties -> C/C++ Build -> Settings.

from the terminal, do a which g++ to find out where your proper version of g++ is installed. Mine is in /opt/local/bin/g++

Click on GCC C++ Compiler, and fill in the command with it's full path (eg. /opt/local/bin/g++). Click on Miscellaneous to make sure you add the -std=c++11 flag.

Do the same thing for GCC C Compiler (set the command to the full path /opt/local/bin/g++), The GCC C++ Linker (/opt/local/bin/g++), and the GCC Assembler (/opt/local/bin/as).

This FINALLY worked for me, I hope it solves your problem!

like image 120
Cinderhaze Avatar answered Oct 21 '22 12:10

Cinderhaze


MacPorts installs gcc to /opt/local/bin, leaving /usr/bin untouched. The former is apparently higher precedence in the default shell $PATH, so the shell will find the gcc under /opt/local/bin, even though /usr/bin/gcc still points to the mac LLVM-gcc-4.2 compiler. Eclipse apparently does not set up $PATH the same way as the terminal, and so finds the /usr/bin/ version.

I was able to fix this by manually symlinking /usr/bin/{gcc,g++} to the MacPorts versions.

like image 42
trbabb Avatar answered Oct 21 '22 11:10

trbabb