为什么CMake拒绝使用非默认编译器? [英] Why does CMake refuse to use a non-default compiler?

查看:393
本文介绍了为什么CMake拒绝使用非默认编译器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to check whether my C++ project compiles on an older version of GCC. For this reason I have installed the older version and want CMake to use it to compile my project.

CMake常见问题解答更改编译器告诉我这是正确的方法:

The CMake FAQ on changing the compiler tells me that this is the right way to do it:

CC=gcc-4.4 CXX=g++-4.4 cmake -G "Unix Makefiles" ..

这就是我键入的内容和CMake似乎运行良好:

So this is what I typed and CMake seems to run fine:

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,我发现:

However, looking at CMakeCache.txt now I find this:

//CXX compiler.
CMAKE_CXX_COMPILER:FILEPATH=/usr/bin/c++

显然CMake没有使用我指定的编译器。当我将此行更改为使用g ++-4.4并再次运行CMake时,它将创建一个无限循环:

Obviously CMake did not use the compiler I specified. When I change this line to use g++-4.4 and run CMake again it will create an endless loop:

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

Why does CMake not use the compiler I specify and how can I fix this?

推荐答案

通过您提供的链接:


不能保证此方法适用于所有生成器

This method is not guaranteed to work for all generators

使用第二种方法:


cmake -G您的生成器 -D CMAKE_C_COMPILER = gcc-4.4 -D CMAKE_CXX_COMPILER = g ++-4.4路径/到/您的/源

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

如果没有帮助:


  1. 使用绝对路径

  2. 不要忘记在构建目录中清理所有

  1. use absolute path
  2. do not forget to clean all in build directory

这篇关于为什么CMake拒绝使用非默认编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆