Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change cmake compiler from clang to g++ for mac

I am working with a very inconvenient software, and it doesn't support clang. So, I am required to change my cmake compiler and as I read almost everywhere, and here How can I make CMake use GCC instead of Clang on Mac OS X?, I tried :

cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++

However, I am still getting this error

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

GAMBIT does not support the Clang compiler. Please choose another compiler.

-- Configuring incomplete, errors occurred!

Any suggestion, please?

like image 827
ShS Avatar asked Sep 28 '17 14:09

ShS


People also ask

What is the <Lang> compiler in CMake?

This is the command that will be used as the <LANG> compiler. Once set, you can not change this variable. This variable can be set by the user during the first time a build tree is configured. If a non-full path value is supplied then CMake will resolve the full path of the compiler.

How do I compile a C++ project with Clang?

If the default compiler chosen by cmake is gcc and you have installed clang, you can use the easy way to compile your project with clang: $ mkdir build && cd build $ CXX=clang++ CC=clang cmake.. $ make -j2

How do I switch from GCC to Clang?

To switch between gcc and clang, you should have two completely separate build trees, and simply cd back and forth to "switch" compilers. Once a build tree is generated with a given compiler, you cannot switch the compiler for that build tree.

How do I set up clang on macOS?

The order the compilers appear in the list depends on your PATH. On the C/C++ Configuration screen, scroll down and expand Advanced Settings and ensure that Mac framework path points to the system header files. For example: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks VS Code is now configured to use Clang on macOS.


2 Answers

I've found setting environment variables CC and CXX before running CMake for the first time peferrable to messing with CMAKE_CXX_COMPILER. Also note that it's probably a good idea to set both. So get into an empty binary directory and run this:

CC=/usr/bin/gcc CXX=/usr/bin/g++ cmake ...

Also make sure that /usr/bin/gcc is really GCC and not e.g. a symlinked or otherwise disguised Clang (I believe such setup can exist in the MacOS world).

like image 50
Angew is no longer proud of SO Avatar answered Oct 21 '22 07:10

Angew is no longer proud of SO


You probably need to set CMAKE_C_COMPILER as well, that is:

cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++ -DCMAKE_C_COMPILER=/usr/bin/gcc

Indeed, looking at Gambit source code, it seems it's mostly C.

Personally, I usually like to set both, just in case.

like image 2
valiano Avatar answered Oct 21 '22 07:10

valiano