-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
windows cmake use clang-cl with Ninja during configuration process crashed #2257
Comments
Same on Windows 7 while configuring from VS Code 1.70 with Ninja 1.11.1, CMake 3.25.0, CCache 4.7.3 and Clang 16.0.0:
|
This issue happens when I pair CMake and ninja for any compiler, somehow meson + ninja works flawlessly, I couldn't find the root cause |
I had the same problem. I found the explanation and solution here: https://discourse.cmake.org/t/rc-rc-mt-cmake-mt-notfound/5089/5 To sum up, run vcvarsall.bat before to call the CMake generation: In my case:
So call your cmake command line generation:
It is important to pass both -DCMAKE_C_COMPILER=clang-cl and -DCMAKE_CXX_COMPILER=clang-cl, because if you don't do that Cmake complains that you are specifying Clang as one compiler ad MSVC as another one, what it is not allowed, giving out an error as result. |
A more complete link is here: https://ezengine.net/pages/docs/build/clang-on-windows.html |
Thank you for your words of wisdom @acesolucoes, But I don't have VS 2022 where I'm using ninja, I have tested in 2 different systems where I have VS 2022 and all compilers (Clang, g++, gcc) with ninja and other system with only g++/clang/gcc with ninja. I generated project using VS back end with cl-compiler, cmake generates and compiles them them successfully, but if I try to generate for ninja as back end it fails and generates this error (if I set the CMAKE_CXX_COMPILER_WORKS flag off) PS F:\tc\build> cmake . -G "Ninja" -B .\build\
-- The CXX compiler identification is GNU 11.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: D:/m/gcc/bin/c++.exe
-- Check for working CXX compiler: D:/m/gcc/bin/c++.exe - broken
CMake Error at D:/m/CMake/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
The C++ compiler
"D:/m/gcc/bin/c++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: F:/tc/build/build/CMakeFiles/CMakeScratch/TryCompile-r29la2
Run Build Command(s):D:/m/gcc/bin/ninja.exe -v cmTC_c3367 && [1/2] D:\m\gcc\bin\c++.exe -o CMakeFiles/cmTC_c3367.dir/testCXXCompiler.cxx.obj -c F:/tc/build/build/CMakeFiles/CMakeScratch/TryCompile-r29la2/testCXXCompiler.cxx
[2/2] cmd.exe /C "cd . && D:\m\gcc\bin\c++.exe CMakeFiles/cmTC_c3367.dir/testCXXCompiler.cxx.obj -o cmTC_c3367.exe -Wl,--out-implib,libcmTC_c3367.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
FAILED: cmTC_c3367.exe
cmd.exe /C "cd . && D:\m\gcc\bin\c++.exe CMakeFiles/cmTC_c3367.dir/testCXXCompiler.cxx.obj -o cmTC_c3367.exe -Wl,--out-implib,libcmTC_c3367.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
The system cannot find the path specified.
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred! If I enable that flag cmake generated as I've told it to but fails at the linking stage PS F:\tc\build> ninja
[2/4] Linking CXX shared library libmylibrary.dll
FAILED: libmylibrary.dll lib/libmylibrary.dll.a
cmd.exe /C "cd . && D:\m\gcc\bin\g++.exe -g -shared -o libmylibrary.dll -Wl,--out-implib,lib\libmylibrary.dll.a -Wl,--major-image-version,0,--minor-image-version,0 CMakeFiles/mylibrary.dir/lib.cpp.obj -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
The system cannot find the path specified.
[3/4] Building CXX object CMakeFiles/myexecutable.dir/main.cpp.obj
ninja: build stopped: subcommand failed. But make works with or without the flag enabled, and compiles successfully using g++, since make is slow and always try to compile even when the compiled files are present in the build directory I wanted ninja as my build system and due to this problem I'm falling back to make. P.S I cant install VS 2022 in my other system, if that could be possible I can use MSbuild rather than Ninja |
Well @silversurfer98 , the first thing you must pay attention is gcc on Windows generates executables using a different ABI than MSVC, something more like the ABI that it uses on Linux, meanwhile clang efforts to be ABI compliant with the "natural" compiler for the plataform, that is, it generates an executable and libraries with ABIs compatible with GCC on Linux and compatible with MSVC ABI on Windows.
I had installed MSVC2022, but I am not sure it is a dependency when using this command line. I believe it is not. So, I think that it worths to take the shot using that for your case. |
Again thank you very much on such faster reply @acesolucoes, Unfortunately still clang++ generates same error, P.S I didn't use the VS2022 clang, I used latest MinGW build 12.2.0 PS F:\tc> cmake . -D CMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -D CMAKE_BUILD_TYPE=Release -G "Ninja" -B .\build\
-- The CXX compiler identification is Clang 16.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: D:/m/gcc/bin/clang++.exe
-- Check for working CXX compiler: D:/m/gcc/bin/clang++.exe - broken
CMake Error at D:/m/CMake/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
The C++ compiler
"D:/m/gcc/bin/clang++.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: F:/tc/build/CMakeFiles/CMakeScratch/TryCompile-73dfr0
Run Build Command(s):D:/m/gcc/bin/ninja.exe -v cmTC_20661 && [1/2] D:\m\gcc\bin\clang++.exe -MD -MT CMakeFiles/cmTC_20661.dir/testCXXCompiler.cxx.obj -MF CMakeFiles\cmTC_20661.dir\testCXXCompiler.cxx.obj.d -o CMakeFiles/cmTC_20661.dir/testCXXCompiler.cxx.obj -c F:/tc/build/CMakeFiles/CMakeScratch/TryCompile-73dfr0/testCXXCompiler.cxx
[2/2] cmd.exe /C "cd . && D:\m\gcc\bin\clang++.exe CMakeFiles/cmTC_20661.dir/testCXXCompiler.cxx.obj -o cmTC_20661.exe -Wl,--out-implib,libcmTC_20661.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
FAILED: cmTC_20661.exe
cmd.exe /C "cd . && D:\m\gcc\bin\clang++.exe CMakeFiles/cmTC_20661.dir/testCXXCompiler.cxx.obj -o cmTC_20661.exe -Wl,--out-implib,libcmTC_20661.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
The system cannot find the path specified.
ninja: build stopped: subcommand failed.
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:3 (project)
-- Configuring incomplete, errors occurred! If you can find a work around that I would be very thankful, Make takes minimum 3 mins for even small projects And I have ran the vcvars64.bat also for testing in my VS2022 setup, it fails |
Sorry, I don't have a clue in what to do in order to fix that. Though I have a tip: You can use the verbose command line option:
it will give you a more complete output and might emit a more reasonable message describing the error that causes the compilation to fail. |
Hi @acesolucoes I have tried it with --log-level=VERBOSE, It errors out saying .obj file not found, I couldn't understand why it can't compile |
Sorry. Neither I. I presume that some executable is missing, and the compilation pipeline fails due to some crucial step not running as expected. |
With the first comment, When you're using "clang-cl" it's going to pick up an easy path for compiling for Windows, whether you are on Linux or Windows. It gets more complicated if you switch to clang/clang++ as most CMakeLists will go down a different path. You can use |
@acesolucoes Thank you for your response and suggestions and sorry for late reply. Unfortunately, even after following your advice and downloading clang for Windows from the official release pages, updating the path for the clang, clang++, and other executables in the system path, and passing the absolute path in the command line, the compilation pipeline still fails with errors. @Downchuck Hi, thank you for your insights, but I've tried your solution ultimately ninja + cmake + windows without any VS is not a good combination Once again @acesolucoes Thank you very much |
If you want to stick with clang maybe you could use https://github.com/mstorsjo/llvm-mingw? |
@rfl890 I will try that, thanks for this |
Its not working same error rises, And I'm gonna leave it and learn Dev Containers, Gonna raise ticket for installing docker or podman xD |
I found a compilation issue, which I checked and found to be ninja related. More specifically:
All use cases use the command line environment.
There are command line two enviroment
More specifically:
Here are the c file
test.c
Obviously clang-cl compiles directly
cmake-test
, below are some details:The command result
Also works fine
//the command
The command result
I observed a difference between the actual link command and compiling it directly from clang-cl, which is available directly from the windows command line
The text was updated successfully, but these errors were encountered: