The strange thing is that it can WORK when I type the cmake command directly on the Terminal:
Click to expand
F:\Git-Repo\cmake-conan-setup>cmake --preset win32-clang-x64-ninja-debug
Preset CMake variables:
CMAKE_BUILD_TYPE="Debug"
CMAKE_CXX_COMPILER="clang++.exe"
CMAKE_C_COMPILER="clang.exe"
CMAKE_INSTALL_PREFIX:PATH="F:/Git-Repo/cmake-conan-setup/install/win32-clang-x64-ninja-debug"
Preset environment variables:
PATH="C:/Program Files/LLVM/bin;C:\Python\Python310\Scripts\;C:\Python\Python310\;C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\dotnet\;C:\Program Files\CMake\bin;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\gsudo\;C:\Program Files\NASM;C:\Program Files\Git\cmd;C:\Program Files\Typora;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build;C:\Users\hwhsu1231\AppData\Local\Microsoft\WindowsApps;C:\Users\hwhsu1231\.dotnet\tools;"
-- The C compiler identification is Clang 15.0.2 with GNU-like command-line
-- The CXX compiler identification is Clang 15.0.2 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/LLVM/bin/clang.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:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
========== cmake-conan-setup ==========
-- Configuring done
-- Generating done
-- Build files have been written to: F:/Git-Repo/cmake-conan-setup/build/win32-clang-x64-ninja-debug
However, when I used VSCode + CMake Tools to do that, it FAILED with the following error message:
Click to expand
[main] Configuring folder: cmake-conan-setup
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=F:/Git-Repo/cmake-conan-setup/install/win32-clang-x64-ninja-debug -SF:/Git-Repo/cmake-conan-setup -BF:/Git-Repo/cmake-conan-setup/build/win32-clang-x64-ninja-debug -G Ninja
[cmake] -- The C compiler identification is Clang 15.0.2 with GNU-like command-line
[cmake] -- The CXX compiler identification is Clang 15.0.2 with GNU-like command-line
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - failed
[cmake] -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe
[cmake] -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - broken
[cmake] CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):
[cmake] The C compiler
[cmake]
[cmake] "C:/Program Files/LLVM/bin/clang.exe"
[cmake]
[cmake] is not able to compile a simple test program.
[cmake]
[cmake] It fails with the following output:
[cmake]
[cmake] Change Dir: F:/Git-Repo/cmake-conan-setup/build/win32-clang-x64-ninja-debug/CMakeFiles/CMakeTmp
[cmake]
[cmake] Run Build Command(s):C:/PROGRA~1/CMake/bin/ninja.exe cmTC_bc09b && [1/2] Building C object CMakeFiles/cmTC_bc09b.dir/testCCompiler.c.obj
[cmake] [2/2] Linking C executable cmTC_bc09b.exe
[cmake] FAILED: cmTC_bc09b.exe
[cmake] cmd.exe /C "cd . && C:\PROGRA~1\LLVM\bin\clang.exe -fuse-ld=lld-link -nostartfiles -nostdlib -g -Xclang -gcodeview -O0 -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -Xlinker /subsystem:console CMakeFiles/cmTC_bc09b.dir/testCCompiler.c.obj -o cmTC_bc09b.exe -Xlinker /MANIFEST:EMBED -Xlinker /implib:cmTC_bc09b.lib -Xlinker /pdb:cmTC_bc09b.pdb -Xlinker /version:0.0 -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames && cd ."
[cmake] lld-link: error: <root>: undefined symbol: mainCRTStartup
[cmake] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[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:3 (project)
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake] See also "F:/Git-Repo/cmake-conan-setup/build/win32-clang-x64-ninja-debug/CMakeFiles/CMakeOutput.log".
[cmake] See also "F:/Git-Repo/cmake-conan-setup/build/win32-clang-x64-ninja-debug/CMakeFiles/CMakeError.log".
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" -DCMAKE_C_COMPILER=clang.exe -DCMAKE_CXX_COMPILER=clang++.exe -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=F:/Git-Repo/cmake-conan-setup/install/win32-clang-x64-ninja-debug -SF:/Git-Repo/cmake-conan-setup -BF:/Git-Repo/cmake-conan-setup/build/win32-clang-x64-ninja-debug -G Ninja exited with code: 1 and signal: null
Here are the generated CMakeOutput.log and CMakeError.log :
[cmake] The C compiler
[cmake]
[cmake] "C:/Program Files/LLVM/bin/clang.exe"
[cmake]
[cmake] is not able to compile a simple test program.
This error is similar with the one in this topic, in which I used with MinGW compiler. However this time, I indeed append the C:/Program Files/LLVM/bin to the PATH env. And it only failed with CMake Tools.
If I were to guess, there’s more to the environment to use this compiler than setting PATH up to have the compiler around. Can you compare the environment in the shell that works against one where it doesn’t?
Can you get CMake to run set inside of execute_process or something? Or “mock up” CMake as a batch script that runs set and then forwards arguments to a real CMake?