Cmake doesn't honour -D CMAKE_CXX_COMPILER=g++

后端 未结 2 1238
慢半拍i
慢半拍i 2021-01-11 10:27

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 a

相关标签:
2条回答
  • 2021-01-11 10:49

    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.

    Source: 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.

    0 讨论(0)
  • 2021-01-11 10:56

    I do it like this instead:

    CXX=/usr/bin/g++ cmake ../src/CMakeLists.txt
    
    0 讨论(0)
提交回复
热议问题