简体   繁体   English

Cmake不尊重-D CMAKE_CXX_COMPILER = g ++

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

I'm trying to force cmake to build my cpp code with g++, as by default it uses clang instead. 我正在尝试强制cmake用g ++构建我的cpp代码,因为默认它使用clang代替。 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 所以我使用: cmake -D CMAKE_CXX_COMPILER=g++ ../src/CMakeLists.txt ,然后cmake检查gcc和g ++(成功),但仍然make VERBOSE=1产量

/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 

As it calls /usr/bin/c++ not /usr/bin/g++ I concur it still uses clang. 因为它调用/ usr / bin / c ++而不是/ usr / bin / g ++我同意它仍然使用clang。 Any idea what's the problem? 知道问题是什么? I know I have g++ and it's in /usr/bin/. 我知道我有g ++,它在/ usr / bin /中。 I'm running Mac OS X 10.8.2 我正在运行Mac OS X 10.8.2

CMAKE_CXX_COMPILER can only be set the first time cmake is run in a given build directory. CMAKE_CXX_COMPILER只能在给定构建目录中第一次运行cmake时设置。 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. 要更改CMAKE_CXX_COMPILER,首先需要删除构建目录的内容,然后使用该选项再次运行cmake。

Source: http://www.cmake.org/Wiki/CMake_Useful_Variables 资料来源: http//www.cmake.org/Wiki/CMake_Useful_Variables

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无论如何都必须从头开始。

我是这样做的:

CXX=/usr/bin/g++ cmake ../src/CMakeLists.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM