Cmake 不尊重 -D CMAKE_CXX_COMPILER=g++ [英] Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++

查看:57
本文介绍了Cmake 不尊重 -D CMAKE_CXX_COMPILER=g++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试强制 cmake 使用 g++ 构建我的 cpp 代码,因为默认情况下它使用 clang.所以我使用: cmake -D CMAKE_CXX_COMPILER=g++ ../src/CMakeLists.txt 之后 cmake 检查 gcc 和 g++ (成功),但仍然 make VERBOSE=1 产量

I'm trying to force cmake to build my cpp code with g++, as by default it uses clang instead. So I use: cmake -D CMAKE_CXX_COMPILER=g++ ../src/CMakeLists.txt after which cmake checks for gcc and g++ (with success), but nonetheless make VERBOSE=1 yields

/usr/bin/c++     -o CMakeFiles/trial_cpp.dir/trial.cpp.o -c "/Users/Kuba/Code/Sketchpad/Trial     project/src/trial.cpp"
Linking CXX executable trial_cpp
/opt/etlocal/bin/cmake -E cmake_link_script CMakeFiles/trial_cpp.dir/link.txt --verbose=1
/usr/bin/c++    -Wl,-search_paths_first -Wl,-headerpad_max_install_names   CMakeFiles/trial_cpp.dir/trial.cpp.o  -o trial_cpp 

因为它调用/usr/bin/c++ 而不是/usr/bin/g++ 我同意它仍然使用 clang.知道有什么问题吗?我知道我有 g++,它在/usr/bin/中.我正在运行 Mac OS X 10.8.2

As it calls /usr/bin/c++ not /usr/bin/g++ I concur it still uses clang. Any idea what's the problem? I know I have g++ and it's in /usr/bin/. I'm running Mac OS X 10.8.2

推荐答案

CMAKE_CXX_COMPILER 只能在 cmake 第一次在给定的构建目录中运行时设置.在随后的运行中,它被忽略.要更改 CMAKE_CXX_COMPILER,您首先需要删除构建目录的内容,然后使用该选项再次运行 cmake.

CMAKE_CXX_COMPILER can only be set the first time cmake is run in a given build directory. On subsequent runs it is ignored. In order to change CMAKE_CXX_COMPILER you first need to delete the contents of the build directory and then run cmake again with that option.

来源:http://www.cmake.org/Wiki/CMake_Useful_Variables

我认为仅在第一次运行时使用该变量的原因是因为以后更改它可能会使已构建的所有内容(包括配置检查)无效,因此 cmake 无论如何都必须从头开始.

I believe the reasoning for only using that variable on the first run is because changing it later would potentially invalidate everything already built including the configuration checks so cmake would have to start from scratch anyway.

这篇关于Cmake 不尊重 -D CMAKE_CXX_COMPILER=g++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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