我想检查我的 C++ 项目是否可以在旧版本的 GCC 上编译。因此,我安装了旧版本并希望 CMake 使用它来编译我的项目。
CMake 常见问题解答关于更改编译器 http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F告诉我这是正确的方法:
CC=gcc-4.4 CXX=g++-4.4 cmake -G "Unix Makefiles" ..
这就是我输入的内容,CMake 似乎运行良好:
chris@chris-machine:~/projects/myProject/build$ CC=gcc-4.4 CXX=g++-4.4 cmake -G "Unix Makefiles" ..
-- Found PythonInterp: /usr/bin/python (found version "2.7.4")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/chris/projects/myProject/build
但是,现在查看 CMakeCache.txt 我发现:
//CXX compiler.
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++
显然CMake没有使用我指定的编译器。当我更改此行以使用 g++-4.4 并再次运行 CMake 时,它将创建一个无限循环:
chris@chris-machine:~/projects/myProject/build$ CC=gcc-4.4 CXX=g++-4.4 cmake -G "Unix Makefiles" ..
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/g++-4.4
-- Found PythonInterp: /usr/bin/python (found version "2.7.4")
-- Looking for include file pthread.h
-- Looking for include file pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Configuring done
You have changed variables that require your cache to be deleted.
Configure will be re-run and you may have to reset some variables.
The following variables have changed:
CMAKE_CXX_COMPILER= /usr/bin/g++-4.4
-- Found PythonInterp: /usr/bin/python (found version "2.7.4")
// and so on...
为什么 CMake 不使用我指定的编译器以及如何解决此问题?