2026-05-21 7:25 AM
I am currently experiencing the following problem on Windows 11:
I have STM32CubeCLT 1.20.0 installed, respective directories are correctly added to the front of system PATH, no problems when (cross)compiling with CMake, Ninja and arm-none-eabi toolchain for an STM32 target.
I have to run unit tests on my host machine, for that i use MSYS2 with the UCRT64 environment. To integrate into a common CMake script, i cannot only use the MSYS2 environment from the UCRT64 shell, i therefore added C:\msys64\ucrt64\bin to the back of system PATH.
With this constellation, i cannot use the gcc provided by MSYS2 UCRT64. I used this simple setup:
main.c
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(test)
add_executable(test main.c)
Then running cmake -B build -S . -G Ninja leads to
cmake -B build -S . -G Ninja
-- 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/ucrt64/bin/cc.exe
-- Check for working C compiler: C:/msys64/ucrt64/bin/cc.exe - broken
CMake Error at C:/ST/STM32CubeCLT_1.20.0/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"C:/msys64/ucrt64/bin/cc.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: 'C:/data/compile_test/build/CMakeFiles/CMakeScratch/TryCompile-i8my41'
Run Build Command(s): C:/ST/STM32CubeCLT_1.20.0/Ninja/bin/ninja.exe -v cmTC_29df4
[1/2] C:\msys64\ucrt64\bin\cc.exe -o CMakeFiles\cmTC_29df4.dir\testCCompiler.c.obj -c C:\data\compile_test\build\CMakeFiles\CMakeScratch\TryCompile-i8my41\testCCompiler.c
FAILED: CMakeFiles/cmTC_29df4.dir/testCCompiler.c.obj
C:\msys64\ucrt64\bin\cc.exe -o CMakeFiles\cmTC_29df4.dir\testCCompiler.c.obj -c C:\data\compile_test\build\CMakeFiles\CMakeScratch\TryCompile-i8my41\testCCompiler.c
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:2 (project)
-- Configuring incomplete, errors occurred!
If i however place the C:\msys64\ucrt64\bin to the front of the system Path, for example (temporarily) by executing $env:Path = "C:\msys64\ucrt64\bin;" + $env:Path everything works fine:
cmake -B build -S . -G Ninja
-- The C compiler identification is GNU 16.1.0
-- The CXX compiler identification is GNU 16.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/ucrt64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/ucrt64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (3.9s)
-- Generating done (0.0s)
-- Build files have been written to: C:/data/compile_test/build
I am absolutely able to work around the problem by doing exactly that, prepending the msys2 environment, but I still want to figure out where the problem lies.