CMake Specify Compiler

Back

  • cmake -DCMAKE_C_COMPILER:FILEPATH=/path/to/gcc-11 -DCMAKE_CXX_COMPILER:FILEPATH=/path/to/g++-11 ..
  • export CC=/path/to/gcc-11
  • export CXX=/path/to/gcc-11
  • make <target>

Note: CMAKE_C_COMPILER should not be set in CMakeLists with set instead we pass it as an argument and get it checked in CMakeCache

See this question and this stackoverflow question