为什么CMake的拒绝使用非默认的编译器?(Why does CMake refuse to use

2019-10-18 13:18发布

我想看看我的C ++项目是否编译的是较旧版本的GCC。 为此,我已经安装了旧版本,并希望CMake的用它来编译我的项目。

CMake的FAQ 上改变编译器告诉我,这是做的正确方法:

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的不使用我指定的编译器,我怎么能解决这个问题?

Answer 1:

从链接您提供:

此方法不能保证对所有发电机工作

使用第二种方法:

cmake的-G “您的发电机” -D CMAKE_C_COMPILER = GCC-4.4 -D CMAKE_CXX_COMPILER =克++ - 4.4路径/到/你的/源

如果没有帮助:

  1. 使用绝对路径
  2. 不要忘了清理所有在建目录


Answer 2:

我已经遇到这个问题,准确和。 显然,这是一个的CMake“不会解决”的问题: https://cmake.org/Bug/view.php?id=14841

一个解决办法是删除CMakeCXXCompiler.cmake要重新生成你的build目录,每次生成目录的CMakeFiles目录内的文件。

路径应该是: build_directory/CMakeFiles/CMAKE_VERSION/CMakeCXXCompiler.cmake 。 在Linux上,你可以得到你CMAKE_VERSION以编程cmake --version | cut -d ' ' -f 3 cmake --version | cut -d ' ' -f 3

一个整洁的“修复”将是简单的添加删除包含文件到您的构建脚本时,你预计你会遇到这样。



文章来源: Why does CMake refuse to use a non-default compiler?
标签: cmake