无法在 MinGW64 / MSYS 下的 CMake 中指定非默认 C/C++ 编译器
Cannot specify a non default C/C++ compiler in CMake under MinGW64 / MSYS
从Mingw-w64开始,CMake找不到我在命令行指定的非默认编译器。
这是构建前的输出:
MINGW64 /C/projects/TEST
$ cmake -G "MSYS Makefiles" -D CMAKE_C_COMPILER=/mingw64/bin/gcc -D CMAKE_CXX_COMPILER=/mingw64/bin/g++ ../Test-LineHandler
Sub-project name: Test
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
CMake Error at CMakeLists.txt:16 (project):
The CMAKE_C_COMPILER:
C:/msys64/mingw64/bin/gcc
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:16 (project):
The CMAKE_CXX_COMPILER:
C:/msys64/mingw64/bin/g++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/projects/TEST/CMakeFiles/CMakeOutput.log".
但是,gcc
和g++
都存在:
$ ls -l C:/msys64/mingw64/bin/gcc
-rwxr-xr-x 1 RFT RFT 2218766 Dec 10 00:50 C:/msys64/mingw64/bin/gcc
$ ls -l C:/msys64/mingw64/bin/g++
-rwxr-xr-x 1 RFT RFT 2221326 Dec 10 00:50 C:/msys64/mingw64/bin/g++
$ ls -l /mingw64/bin/gcc
-rwxr-xr-x 1 RFT RFT 2218766 Dec 10 00:50 /mingw64/bin/gcc
$ ls -l /mingw64/bin/g++
-rwxr-xr-x 1 RFT RFT 2221326 Dec 10 00:50 /mingw64/bin/g++
这是生成的 CMakeOutput.log
文件:
$ more ./CMakeFiles/CMakeOutput.log
The system is: Windows - 10.0.19041 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: C:/msys64/mingw64/bin/gcc
Build flags:
Id flags:
The output was:
0
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.exe"
The C compiler identification is GNU, found in "C:/projects/TEST/CMakeFiles/3.19.3/CompilerIdC/a.exe"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/msys64/mingw64/bin/g++
Build flags:
Id flags:
The output was:
0
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.exe"
The CXX compiler identification is GNU, found in "C:/projects/TEST/CMakeFiles/3.19.3/CompilerIdCXX/a.exe"
我是否在命令行中正确指定了非默认编译器?
确切的错误是:C:/msys64/mingw64/bin/gcc is not a full path to an existing compiler tool.
这是正确的,因为完整路径是 C:/msys64/mingw64/bin/gcc.exe
。
因此只需包含指定编译器的 .exe
扩展。
从Mingw-w64开始,CMake找不到我在命令行指定的非默认编译器。
这是构建前的输出:
MINGW64 /C/projects/TEST
$ cmake -G "MSYS Makefiles" -D CMAKE_C_COMPILER=/mingw64/bin/gcc -D CMAKE_CXX_COMPILER=/mingw64/bin/g++ ../Test-LineHandler
Sub-project name: Test
-- The C compiler identification is GNU 10.2.0
-- The CXX compiler identification is GNU 10.2.0
CMake Error at CMakeLists.txt:16 (project):
The CMAKE_C_COMPILER:
C:/msys64/mingw64/bin/gcc
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:16 (project):
The CMAKE_CXX_COMPILER:
C:/msys64/mingw64/bin/g++
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
See also "C:/projects/TEST/CMakeFiles/CMakeOutput.log".
但是,gcc
和g++
都存在:
$ ls -l C:/msys64/mingw64/bin/gcc
-rwxr-xr-x 1 RFT RFT 2218766 Dec 10 00:50 C:/msys64/mingw64/bin/gcc
$ ls -l C:/msys64/mingw64/bin/g++
-rwxr-xr-x 1 RFT RFT 2221326 Dec 10 00:50 C:/msys64/mingw64/bin/g++
$ ls -l /mingw64/bin/gcc
-rwxr-xr-x 1 RFT RFT 2218766 Dec 10 00:50 /mingw64/bin/gcc
$ ls -l /mingw64/bin/g++
-rwxr-xr-x 1 RFT RFT 2221326 Dec 10 00:50 /mingw64/bin/g++
这是生成的 CMakeOutput.log
文件:
$ more ./CMakeFiles/CMakeOutput.log
The system is: Windows - 10.0.19041 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: C:/msys64/mingw64/bin/gcc
Build flags:
Id flags:
The output was:
0
Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.exe"
The C compiler identification is GNU, found in "C:/projects/TEST/CMakeFiles/3.19.3/CompilerIdC/a.exe"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/msys64/mingw64/bin/g++
Build flags:
Id flags:
The output was:
0
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.exe"
The CXX compiler identification is GNU, found in "C:/projects/TEST/CMakeFiles/3.19.3/CompilerIdCXX/a.exe"
我是否在命令行中正确指定了非默认编译器?
确切的错误是:C:/msys64/mingw64/bin/gcc is not a full path to an existing compiler tool.
这是正确的,因为完整路径是 C:/msys64/mingw64/bin/gcc.exe
。
因此只需包含指定编译器的 .exe
扩展。