I just built the latest version of Clang, and I'm trying to use it to compile a program with Cmake. If I try clang++.exe HelloWorld.cpp -o HelloWorld.exe
, it compiles and runs fine. When I try to build with Cmake, I get the following output.
-- The CXX compiler identification is Clang 21.0.0 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: J:/shares/clang/llvm-project/build/Release/bin/clang.exe
-- Check for working C compiler: J:/shares/clang/llvm-project/build/Release/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-4.0/Modules/CMakeTestCCompiler.cmake:67 (message):
The C compiler
"J:/shares/clang/llvm-project/build/Release/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: 'C:/shares/projects/j2inet/devsetup/Clang/HelloWorld/HelloWorld/HelloWorld/build/CMakeFiles/CMakeScratch/TryCompile-43s7yv'
Run Build Command(s): J:/shares/Ninja/ninja.exe -v cmTC_1acda
[1/2] J:\shares\clang\llvm-project\build\Release\bin\clang.exe -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview -MD -MT CMakeFiles/cmTC_1acda.dir/testCCompiler.c.obj -MF CMakeFiles\cmTC_1acda.dir\testCCompiler.c.obj.d -o CMakeFiles/cmTC_1acda.dir/testCCompiler.c.obj -c C:/shares/projects/j2inet/devsetup/Clang/HelloWorld/HelloWorld/HelloWorld/build/CMakeFiles/CMakeScratch/TryCompile-43s7yv/testCCompiler.c
[2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && J:\shares\clang\llvm-project\build\Release\bin\clang.exe -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview -Xlinker /subsystem:console -fuse-ld=lld-link CMakeFiles/cmTC_1acda.dir/testCCompiler.c.obj -o cmTC_1acda.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_1acda.lib -Xlinker /pdb:cmTC_1acda.pdb -Xlinker /version:0.0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
FAILED: cmTC_1acda.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && J:\shares\clang\llvm-project\build\Release\bin\clang.exe -nostartfiles -nostdlib -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -g -Xclang -gcodeview -Xlinker /subsystem:console -fuse-ld=lld-link CMakeFiles/cmTC_1acda.dir/testCCompiler.c.obj -o cmTC_1acda.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_1acda.lib -Xlinker /pdb:cmTC_1acda.pdb -Xlinker /version:0.0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
clang: error: unable to execute command: program not executable
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:7 (project)
This is my CMakeList.txt file.
cmake_minimum_required(VERSION 4.00)
set(CMAKE_C_COMPILER "clang.exe")
set(CMAKE_CXX_COMPILER "clang++.exe")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_SYSTEM_NAME Generic)
project("HelloWorld" )
enable_language(C CXX)
add_executable (HelloWorld "HelloWorld.cpp" "HelloWorld.h")
The build command I am issuing is
cmake -GNinja -DLLVM_ENABLE_PROJECTS=clang ..
Any idea how to fix this?
Thanks to @3CxEZiVlQ for pointing me in the direction of a solution. I needed to add the folder that contained link.exe
to my path. After that, it was able to build fine.