为什么CMake拒绝使用非

我想检查我的C ++项目是否在旧版本的GCC上编译。 为此,我安装了旧版本,并希望CMake使用它来编译我的项目。

关于更改编译器的CMake常见问题解答告诉我,这是实现它的正确方法:

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


从你提供的链接:

这种方法不能保证适用于所有的发电机

使用第二种方法:

cmake -G“Your Generator”-D CMAKE_C_COMPILER = gcc-4.4 -D CMAKE_CXX_COMPILER = g ++ - 4.4 path / to / your / source

如果没有帮助:

  • 使用绝对路径
  • 不要忘记清理全部目录

  • 我也遇到了这个确切的问题。 显然这是CMake中的一个“无法修复”的问题:https://cmake.org/Bug/view.php?id = 14841

    一种解决方法是在每次要重新生成构建目录时,删除构建目录的CMakeFiles目录中的CMakeCXXCompiler.cmake文件。

    路径应该是: build_directory/CMakeFiles/CMAKE_VERSION/CMakeCXXCompiler.cmake 。 在Linux上,您可以通过cmake --version | cut -d ' ' -f 3 CMAKE_VERSION编程方式获得CMAKE_VERSION cmake --version | cut -d ' ' -f 3

    一个简单的“修复”就是只要你预计你会遇到这个问题,就把该文件的删除添加到你的构建脚本中。

    链接地址: http://www.djcxy.com/p/24461.html

    上一篇: Why does CMake refuse to use a non

    下一篇: CMake and compiler warnings