CMakePresets: How to write a proper configurePreset using MinGW compiler?
Problem Descriptions
First of all, I already installed MinGW64 compiler in MSYS with running the following command:
pacman -S mingw-w64-x86_64-toolchain
And I tried the following example of CMakePresets.json
:
Click to expand
{
"version": 5,
"configurePresets": [
{
"name": "win32-gcc-x64-mingw-debug",
"displayName": "Windows GCC x64 (MinGW Makefiles) Debug",
"description": "Using GCC x64 compiler with \"MinGW Makefiles\" geneartor on Windows - Debug",
"generator": "MinGW Makefiles",
"binaryDir": "${sourceDir}/build/${presetName}",
"installDir": "${sourceDir}/install/${presetName}",
"cacheVariables": {
"CMAKE_C_COMPILER": "C:/msys64/mingw64/bin/gcc.exe",
"CMAKE_CXX_COMPILER": "C:/msys64/mingw64/bin/g++.exe",
"CMAKE_MAKE_PROGRAM": "C:/msys64/mingw64/bin/mingw32-make.exe",
"CMAKE_BUILD_TYPE": "Debug"
}
}
],
"buildPresets": [
{
"name": "win32-gcc-x64-mingw-debug",
"displayName": "Windows GCC x64 (MinGW) Debug",
"configurePreset": "win32-gcc-x64-mingw-debug"
}
]
}
However, it failed with the following error message:
Click to expand
F:\Git-Repo\cmake-project-template-conan>cmake --preset win32-gcc-x64-mingw-debug
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_CXX_COMPILER="C:/msys64/mingw64/bin/g++.exe"
CMAKE_C_COMPILER="C:/msys64/mingw64/bin/gcc.exe"
CMAKE_INSTALL_PREFIX:PATH="F:/Git-Repo/cmake-project-template-conan/install/win32-gcc-x64-mingw-debug"
CMAKE_MAKE_PROGRAM="C:/msys64/mingw64/bin/mingw32-make.exe"
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/gcc.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"C:/msys64/mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: F:/Git-Repo/cmake-project-template-conan/build/win32-gcc-x64-mingw-debug/CMakeFiles/CMakeTmp
Run Build Command(s):C:/msys64/mingw64/bin/mingw32-make.exe -f Makefile cmTC_5af10/fast && C:/msys64/mingw64/bin/mingw32-make.exe -f CMakeFiles\cmTC_5af10.dir\build.make CMakeFiles/cmTC_5af10.dir/build
mingw32-make[1]: Entering directory 'F:/Git-Repo/cmake-project-template-conan/build/win32-gcc-x64-mingw-debug/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_5af10.dir/testCCompiler.c.obj
C:\msys64\mingw64\bin\gcc.exe -o CMakeFiles\cmTC_5af10.dir\testCCompiler.c.obj -c F:\Git-Repo\cmake-project-template-conan\build\win32-gcc-x64-mingw-debug\CMakeFiles\CMakeTmp\testCCompiler.c
mingw32-make[1]: *** [CMakeFiles\cmTC_5af10.dir\build.make:77: CMakeFiles/cmTC_5af10.dir/testCCompiler.c.obj] Error 1
mingw32-make[1]: Leaving directory 'F:/Git-Repo/cmake-project-template-conan/build/win32-gcc-x64-mingw-debug/CMakeFiles/CMakeTmp'
mingw32-make: *** [Makefile:126: cmTC_5af10/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred!
See also "F:/Git-Repo/cmake-project-template-conan/build/win32-gcc-x64-mingw-debug/CMakeFiles/CMakeOutput.log".
See also "F:/Git-Repo/cmake-project-template-conan/build/win32-gcc-x64-mingw-debug/CMakeFiles/CMakeError.log".
Here are the generated CMakeOutput.log
and CMakeError.log
:
What do I miss? If the above example is not appropriate, can someone give me a successful example? or how to fix it?
Environments and Versions
- OS version: Windows 11
- Compiler version: GCC 12.2.0
- CMake version: CMake 3.24.2
Edited by Haowei Hsu