提问人:Pixelated Lagg 提问时间:11/10/2023 更新时间:11/10/2023 访问量:58
CMake 无法在 MinGW 上使用 GCC 进行编译
CMake unable to compile with GCC on MinGW
问:
每当我尝试运行 CMake 时,我都会收到此错误:
PS C:\Users\pixil\Desktop\P3D> cmake . -G "MinGW Makefiles"
-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
CMake Error: Generator: execution of make failed. Make command was: C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_df89b/fast &&
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/msys64/ucrt64/bin/gcc.exe
CMake Error: Generator: execution of make failed. Make command was: C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_ee3f9/fast &&
-- Check for working C compiler: C:/msys64/ucrt64/bin/gcc.exe - broken
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.22/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/msys64/ucrt64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/pixil/Desktop/P3D/CMakeFiles/CMakeTmp
Run Build Command(s):C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_ee3f9/fast && The system cannot find the file specified
Generator: execution of make failed. Make command was: C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_ee3f9/fast &&
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!
See also "C:/Users/pixil/Desktop/P3D/CMakeFiles/CMakeOutput.log".
See also "C:/Users/pixil/Desktop/P3D/CMakeFiles/CMakeError.log".
PS C:\Users\pixil\Desktop\P3D>
CMakeError.log 只是重复以下内容:
Detecting C compiler ABI info failed to compile with the following output:
Change Dir: C:/Users/pixil/Desktop/P3D/CMakeFiles/CMakeTmp
Run Build Command(s):C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_74e00/fast && The system cannot find the file specified
Generator: execution of make failed. Make command was: C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_74e00/fast &&
Determining if the C compiler works failed with the following output:
Change Dir: C:/Users/pixil/Desktop/P3D/CMakeFiles/CMakeTmp
Run Build Command(s):C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_62e4a/fast && The system cannot find the file specified
Generator: execution of make failed. Make command was: C:/MinGW/bin/mingw32-make.exe -f Makefile cmTC_62e4a/fast &&
CMakeLists.txt:
set(CMAKE_GENERATOR, "mingw32-make")
cmake_minimum_required(VERSION 3.22.5)
set(CMAKE_C_COMPILER "C:/msys64/ucrt64/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/msys64/ucrt64/bin/g++.exe")
project(p3d)
file(GLOB SOURCES src/*.cpp)
add_executable(p3d ${SOURCES})
target_include_directories(p3d
PRIVATE
${PROJECT_SOURCE_DIR}/src
)
target_link_libraries(p3d
PRIVATE
mingw32
libfreeglut.a
glut32.lib
)
这整个问题只是在我再次干净安装MinGW后才出现的。我已经看到几个解决这个一般问题的 StackOverflow 问题,但没有一个有任何适合我的解决方案。
我验证了我的 PATH 环境变量包含并且 GCC 确实有效。C:/msys64/ucrt64/bin
我都试过了:
set(CMAKE_C_COMPILER "C:/msys64/ucrt64/bin/gcc.exe")
set(CMAKE_CXX_COMPILER "C:/msys64/ucrt64/bin/g++.exe")
和
set(CMAKE_C_COMPILER "gcc")
set(CMAKE_CXX_COMPILER "g++")
在 CMakeLists.txt 中
我所做的一切都没有解决错误。
答: 暂无答案
评论
C:/MinGW/bin/mingw32-make.exe
C:/Users/pixil/Desktop/P3D/CMakeFiles/CMakeTmp
set(CMAKE_GENERATOR, "mingw32-make")
CMAKE_GENERATOR
CMAKE_GENERATOR,
CMakeLists.txt
C:/MinGW
mingw32-make.exe
C:\msys64\ucrt64\bin
C:\msys64\ucrt64\bin
cmake
cmake .
mkdir build; cd build; cmake ..
CMakeCache.txt