更新时间:2023-12-03 23:40:22
As is already written in the answer to the other question, CMake prefers the generic compiler names cc
and c++
when searching for the C and C++ compilers. These probably refer to GNU version 4.1 compilers on your system.
无论如何,要强制CMake在系统路径上使用默认编译器,请将以下代码添加到最外面的CMakeLists.txt
的开头.
Anyway, to force CMake to use the default compilers on the system path, add the following code to the beginning of your outermost CMakeLists.txt
.
find_program(CMAKE_C_COMPILER NAMES $ENV{CC} gcc PATHS ENV PATH NO_DEFAULT_PATH)
find_program(CMAKE_CXX_COMPILER NAMES $ENV{CXX} g++ PATHS ENV PATH NO_DEFAULT_PATH)
...
project (Foo C CXX)
find_program
调用必须在调用project
或enable_language
之前发生.
The find_program
calls must occur before the call to project
or enable_language
.