Switch to gcc compiler

Hi all,

I am using Mac pro 10.9, and the default compiler is clang. I am trying to compile soruce codes via the Terminal, and it gives me a message "CMake Error at CMakeLists.txt:59 (message): Currently, the only supported compiler is GCC(>=4.7). We hope to support Clang soon." How could I switch the compiler from clang to gcc? I have tried Homebrew to install gcc, but it doesn't work.


Thanks!

Mac Pro, OS X Mavericks (10.9.2)

Posted on May 8, 2014 5:19 PM

Reply
12 replies

May 8, 2014 5:41 PM in response to sewen6

sewen6,


you could install the Mavericks version of MacPorts, and install one of their gcc ports — they currently support 4.7.3, 4.8.2, and a beta 4.9. (They support 4.2.4, 4.3.6, 4.4.7, 4.5.4, and 4.6.4 as well.) For example, after installing MacPorts, you should add /opt/local/bin and /opt/local/sbin to your PATH environment variable, and use the following command to install gcc 4.8.2:


sudo port install gcc48


This command will also install all of gcc48’s prerequisite ports. Once gcc48 has been installed, you can check occasionally (e.g. fortnightly) for available updates through these commands:


sudo port selfupdate

sudo port upgrade outdated

May 9, 2014 9:12 PM in response to sewen6

sewen6,


your PATH environment variable looks mostly good; the only things that should be changed are:


  • there should be no space in “/usr /sbin”;
  • you have two copies of /opt/local/bin and /opt/local/sbin in PATH — only one of each is needed; and
  • DYLD_LIBRARY_PATH shouldn’t be in PATH; DYLD_LIBRARY_PATH is supposed to be a separate environment variable which holds library locations.


You’ve got /opt/local/bin and /opt/local/sbin coming before /usr/bin in your PATH, which is the proper place for them.


Have you tried adding -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ to your cmake command line?

May 8, 2014 5:22 PM in response to sewen6

Have you downloaded the GNU gcc source code? Unless things have changed, you have to download the source code then compile that using a C compiler...I always then recompiled using the compiled gcc and then repeated again so I got at least two generations away from the buggy compiler used for the intial compilation.


You then have to replace the name of the compiler you were using with the gcc name and optimization settings.

May 9, 2014 5:17 PM in response to Melophage

Hi Melophage:

I still have some trouble using gcc as compiler. After using the command "sudo port install gcc48" and "sudo port select --set gcc mp-gcc47", I got the message that "Selecting 'mp-gcc48' for 'gcc' succeeded. 'mp-gcc48' is now active.". Moreover, "gcc --version" gives me the mesage that "gcc (MacPorts gcc48 4.8.2_0) 4.8.2". However, when I ran the source code, it still gives the message "CMake Error at CMakeLists.txt:59 (message): Currently, the only supported compiler is GCC(>=4.7). We hope to support Clang soon." Could you help me with it?


Thanks

May 9, 2014 6:27 PM in response to Melophage

Hi Melophage:


I ran the "make clean" command, but it says "make: *** No rule to make target `clean'. Stop." So I deleted the "CMakefiles" in the "build" folder. Does it mean I am able to configure the script from the very beginning? After that I reran the command "cmake -DFETCH_BOOST=TRUE", I still got the message that "

-- The C compiler identification is Clang 5.1.0

-- The CXX compiler identification is Clang 5.1.0

-- Check for working C compiler: /usr/bin/cc

-- Check for working C compiler: /usr/bin/cc -- works

-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - done

-- Check for working CXX compiler: /usr/bin/c++

-- Check for working CXX compiler: /usr/bin/c++ -- works

-- Detecting CXX compiler ABI info

-- Detecting CXX compiler ABI info - done

CMake Error at CMakeLists.txt:59 (message):

Currently, the only supported compiler is GCC(>=4.7). We hope to support

Clang soon.

-- Configuring incomplete, errors occurred!"

May 9, 2014 10:45 PM in response to Melophage

Hi Melophage:


Thanks for pointing out the error. I tried to run the command "cmake .. -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc" in the "build" folder. Is this what you mean by "adding -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ to yourcmake command line" ?

After ranning the command, I got the message:


"CMake Error: The source directory "/Users/wangjie/documents/C++/sailfish-0.6.3/build/CMAKE_CC_COMPILER=gcc" does not exist.

Specify --help for usage, or press the help button on the CMake GUI.

localhost:build wangjie$ cmake .. -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc

CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeDetermineCCompiler.cmake:56 (message):

Could not find compiler set in environment variable CC:


/usr/bin/gcc++.

Call Stack (most recent call first):

CMakeLists.txt:5 (project)



CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_C_COMPILER_ENV_VAR

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_C_COMPILER

CMake Error: Could not find cmake module file: /Users/wangjie/documents/C++/sailfish-0.6.3/build/CMakeFiles/2.8.12.2/CMakeCCom piler.cmake

CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.

Missing variable is:

CMAKE_CXX_COMPILER_ENV_VAR

CMake Error: Could not find cmake module file: /Users/wangjie/documents/C++/sailfish-0.6.3/build/CMakeFiles/2.8.12.2/CMakeCXXC ompiler.cmake

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

-- Configuring incomplete, errors occurred!

See also "/Users/wangjie/documents/C++/sailfish-0.6.3/build/CMakeFiles/CMakeOutput.log".

Segmentation fault: 11".

May 10, 2014 9:16 AM in response to sewen6

sewen6,


I tried to run the command "cmake .. -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc" in the "build" folder. Is this what you mean by "adding -D CMAKE_C_COMPILER=gcc -D CMAKE_CXX_COMPILER=g++ to yourcmake command line" ?

After running the command, I got the message:


CMake Error: The source directory "/Users/wangjie/documents/C++/sailfish-0.6.3/build/CMAKE_CC_COMPILER=gcc" does not exist.

Specify --help for usage, or press the help button on the CMake GUI.


yes, that was what I’d meant, but my understanding is that there needs to a space between each -D option and its parameter, as I’d provided in my suggestion. Your command line looks like there is no space immediately following each -D option.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Switch to gcc compiler

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.