Open crazyCoder1994 opened 1 year ago
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:
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_CXX_COMPILER:string=clang-cl -DCMAKE_CXX_COMPILER_LAUNCHER:string=ccache -DCMAKE_MAKE_PROGRAM:string=ninja -DCMAKE_BUILD_TYPE:string=Debug -DCMAKE_INSTALL_PREFIX:string=<path_to_project>/install/Debug/config-windows-clang-cl-x86_64-debug -DCMAKE_TOOLCHAIN_FILE=<path_to_project>/cmake/x86_64.cmake -DCMAKE_INSTALL_PREFIX=<path_to_project>/install/Debug/config-windows-clang-cl-x86_64-debug -S<path_to_project> -B<path_to_project>/build/Debug/config-windows-clang-cl-x86_64-debug -G Ninja
[cmake] -- The CXX compiler identification is Clang 16.0.0 with MSVC-like command-line
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - failed
[cmake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe
[cmake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang-cl.exe - broken
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCXXCompiler.cmake:63 (message):
[cmake] The C++ compiler
[cmake]
[cmake] "C:/Program Files/LLVM/bin/clang-cl.exe"
[cmake]
[cmake] is not able to compile a simple test program.
[cmake]
[cmake] It fails with the following output:
[cmake]
[cmake] Change Dir: <path_to_project>/build/Debug/config-windows-clang-cl-x86_64-debug/CMakeFiles/CMakeScratch/TryCompile-launv4
[cmake]
[cmake] Run Build Command(s):ninja cmTC_4e413 && [ 50%::0.045 1/2] Building CXX object CMakeFiles\cmTC_4e413.dir\testCXXCompiler.cxx.obj
[cmake] [100%::0.266 2/2] Linking CXX executable cmTC_4e413.exe
[cmake] [31mFAILED: [0mcmTC_4e413.exe
[cmake] cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=CMakeFiles\cmTC_4e413.dir --rc=C:\PROGRA~1\LLVM\bin\llvm-rc.exe --mt=CMAKE_MT-NOTFOUND --manifests -- C:\PROGRA~1\LLVM\bin\lld-link.exe /nologo CMakeFiles\cmTC_4e413.dir\testCXXCompiler.cxx.obj /out:cmTC_4e413.exe /implib:cmTC_4e413.lib /pdb:cmTC_4e413.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
[cmake] MT: command "CMAKE_MT-NOTFOUND /nologo /manifest CMakeFiles\cmTC_4e413.dir/intermediate.manifest /out:CMakeFiles\cmTC_4e413.dir/embed.manifest /notify_update" failed (exit code 0x0) with the following output:
[cmake] Не удается найти указанный файл
[cmake] ninja: build stopped: subcommand failed.
[cmake]
[cmake]
[cmake]
[cmake]
[cmake]
[cmake] CMake will not be able to correctly generate this project.
[cmake] Call Stack (most recent call first):
[cmake] CMakeLists.txt:76 (project)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "<path_to_project>/build/Debug/config-windows-clang-cl-x86_64-debug/CMakeFiles/CMakeOutput.log".
[cmake] See also "<path_to_project>/build/Debug/config-windows-clang-cl-x86_64-debug/CMakeFiles/CMakeError.log".
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_CXX_COMPILER:string=clang-cl -DCMAKE_CXX_COMPILER_LAUNCHER:string=ccache -DCMAKE_MAKE_PROGRAM:string=ninja -DCMAKE_BUILD_TYPE:string=Debug -DCMAKE_INSTALL_PREFIX:string=<path_to_project>/install/Debug/config-windows-clang-cl-x86_64-debug -DCMAKE_TOOLCHAIN_FILE=<path_to_project>/cmake/x86_64.cmake -DCMAKE_INSTALL_PREFIX=<path_to_project>/install/Debug/config-windows-clang-cl-x86_64-debug -S<path_to_project> -B<path_to_project>/build/Debug/config-windows-clang-cl-x86_64-debug -G Ninja exited with code: 1
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:
%programfiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat
So call your cmake command line generation:
cmake -G "Ninja" -B build3 -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl
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. As I have said previously, I sucessfully compiled using clang-cl, but I had to run vcvars.bat. One thing that I tried later is to use clang and clang++ to compile a program. I managed to get it to generate the executable flawlessly. I used the following command-line:
cmake -DCMAKE_CXX_COMPILER="d:/Program Files/LLVM/bin/clang++.exe" -DCMAKE_C_COMPILER="d:/Program Files/LLVM/bin/clang.exe" -G"Ninja" -DCMAKE_BUILD_TYPE=Release -B build .
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 I used those tools because it doesn't need to be installed (No Admin rights)
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:
cmake . -D CMAKE_C_COMPILER="clang" ... --verbose
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.
I never tried to compile using MingW clang++. Only now I payed attention and noticed that you uses clang from MingW. A long time ago when I was using mingW on Windows, I was using gcc. Generally MingW is most associated with gcc and I never tried to use MIngW with ninja. I don't know the version neither the limitations around the clang with MingW neither the limitations of ninja with Mingw.
I recommend you to download clang for Windows from the official release pages (https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.0) - 16.00 is the later version since this writing, to put the path for the clang, clang++ and other executables in system path (the env var PATH) and after that to use your command line from a Windows terminal (like Command prompt or Powershell):
cmake . -D CMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" -D CMAKE_BUILD_TYPE=Release -G "Ninja" -B .\build\
In my case, instead of just clang or clang++ I passed the absolute path. You can try the same thing. So, in this way, maybe you could use Ninja on Windows with clang and clang++ (not clang-cl) without hassle.
Well, my knowledge is dried up with that last hint. I pray for your success, I am rooting for you.
With the first comment, MT: command "CMAKE_MT-NOTFOUND
-- there is a flag, -DCMAKE_MT
to point to an MT executable - presently with clang/llvm, there is a hard coded flag blocking use of llvm-mt, so you'd want to point to an "mt.exe" found from a Microsoft source -- it's likely on your computer if you search for "mt.exe".
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 cmake --debug-trycompile
to keep your files around to debug them. With your error using clang++
you're seeing The system cannot find the path specified.
. It's likely when you debug, you'll see that the "_loc" file it creates does not have the ".exe" suffix appended, and so it is searching for the executable as though it were on a Linux system where there is no file extension.
@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. I've started using make again in meantime xD
@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
@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
test.c
Obviously clang-cl compiles directly
2) I create a cmake project named
cmake-test
, below are some details:The command result
Also works fine
3) But when configure by Ninja, the program crashed //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