I built a simple project to test whether CMake and Ninja could work on my Windows 10. There is a cpp file name test.cpp that is shown below.
#include <iostream>
int main(){
std::cout << "hello world!\n";
return 0;
}
And if I now just use Ninja with the build.ninja file then it can work successfully. So I began to try CMake with a simple CMakeLists.txt file that is shown below.
cmake_minimum_required(VERSION 3.22)
set(CMAKE_CXX_STANDARD 11)
project(test)
add_executable(test test.cpp)
Then I used the command
cmake -B build -G Ninja
And error occured like this:
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: path-to-mingw64/bin/gcc.exe
-- Check for working C compiler: path-to-mingw64/bin/gcc.exe - broken
CMake Error at path-to-cmake/share/cmake3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
The C compiler
"path-to-mingw64/bin/gcc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: path-to-my-test-project/build/CMakeFiles/CMakeTmp
[2/2] Linking C executable cmTC_ed5d0.exe
FAILED: cmTC_ed5d0.exe
cmd.exe /C "cd . && path-to-mingw64\bin\gcc.exe CMakeFiles/cmTC_ed5d0.dir/testCCompiler.c.obj -o cmTC_ed5d0.exe -Wl,--out implib,libcmTC_ed5d0.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 luser32 -lgdi32 -lwinspool -lshell32 -lole32
-loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
CMakeLists.txt:5 (project)
-- Configuring incomplete, errors occurred!
See also "path-to-my-test-project/build/CMakeFiles/CMakeOutput.log".
See also "path-to-my-test-project/build/CMakeFiles/CMakeError.log".
And there are the CMakeOutput.log and CMakeError.log
The system is: Windows - 10.0.19044 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: path-to-mingw64/bin/gcc.exe
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
"path-to-my-test-project/build/CMakeFiles/3.24.2/CompilerIdC/a.exe"
Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: path-to-mingw64/bin/c++.exe
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
"path-to-my-test-project/build/CMakeFiles/3.24.2/CompilerIdCXX/a.exe"
And the CMakeError.log is too long and I don't know how to show, maybe I need some guidance about this.
And also, the command
cmake -B build -G "MinGW Makefiles"
can work successfully.
Just leave me a comment if you require further information.
According to @273K, I add CMakeError.log like this.
Determining if the C compiler works failed with the following output:
Change Dir: path-to-my-test-project/build/CMakeFiles/CMakeTmp
Run Build Command(s):path-to-ninja/ninja.exe cmTC_8d485 && [1/2] Building C object CMakeFiles/cmTC_8d485.dir/testCCompiler.c.obj
[2/2] Linking C executable cmTC_8d485.exe
FAILED: cmTC_8d485.exe
cmd.exe /C "cd . && path-to-mingw64\bin\gcc.exe CMakeFiles/cmTC_8d485.dir/testCCompiler.c.obj -o cmTC_8d485.exe -Wl,--out-implib,libcmTC_8d485.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
ninja: build stopped: subcommand failed.