Tom Macdonald
Tom Macdonald

Reputation: 6593

CMake wants to use ccache instead of gcc

I am trying to use CMake to compile a C++ project on Ubuntu, but I get this error:

CMake Error: your C compiler: "/usr/lib64/ccache/bin/gcc" was not found.   Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: your CXX compiler: "/usr/lib64/ccache/bin/c++" was not found.   Please set CMAKE_CXX_COMPILER to a valid compiler path or name.

I have gcc and everything installed (build-essential on Ubuntu), but I cannot stop cmake from doing this, except by hard-coding CMAKE_C_COMPILER and CMAKE_CXX_COMPILER in CMakeLists.txt, which I am loathe to do for obvious reasons. I tried installing ccache, but that had no effect.

Upvotes: 1

Views: 6659

Answers (2)

ComicSansMS
ComicSansMS

Reputation: 54609

You are not supposed to change CMAKE_C_COMPILER and CMAKE_CXX_COMPILER from within the CMakeLists. Instead you should give them at the command line when running CMake for the first time:

cmake -D CMAKE_CXX_COMPILER=/path/to/g++ ..

Note that this value has no effect after the first run of CMake! So if you want to switch to a different compiler you will either have to delete the CMake cache or switch to a new build directory.

On the other hand, not having to specify this lengthy option for subsequent CMake runs of course also saves a lot of typing.

Upvotes: 3

Hugo Corrá
Hugo Corrá

Reputation: 14799

Take a look on your environment variables:

echo $CC
echo $CXX

if they are empty, try to set them to point to gcc:

$ export CC=/usr/bin/gcc
$ export CXX=/usr/bin/g++

Upvotes: 0

Related Questions