Closed aboelens closed 7 months ago
@aboelens - thanks for reporting the problem. I can repro it, too - running cmake --preset windows-clangcl-x64
from a Developer PowerShell for VS 2022
prompt does fail as you call out. I'll take a look and see what's going on.
TBH, though, running from a Developer PowerShell for VS 2022
for any of the Toolchain files might not be a good idea. Those prompts set environment variables - e.g. IFCPATH
, INCLUDE
, LIBPATH
- that MSVC (and clang, I guess..?) will use, and that might make things precarious. One reason I like the 'toolchain' approach, is because I can switch between targeting different architectures, without launching a new prompt. But when I launch Developer PowerShell for VS 2022
it seems to have set, say, LIB
to x86 paths; so it may appear to work on x86 builds, but I don't know if it's picking up the environment-configured paths, or the Toolchain-configured paths.
mainCRTStartup
should be found in msvcrt[d].lib
, which should be found in a "VC\Tools" folder, like "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\lib\x64". But Windows.Clang.toolchain.cmake
isn't actually adding that as a library path. In a 'plain' command prompt, lld-link.exe
appears to be finding it by itself (through some mechanism/heuristics I haven't looked at yet). But in a Developer PowerShell for VS 2022
prompt, the LIB
environment variable changes lld-link.exe
behavior, and the LIB
environment variable paths are used instead. As I mentioned in my first response, a Developer PowerShell for VS 2022
prompt is initialized for x86 targets by default, and so lld-link.exe
ends-up looking for msvcrt[d].lib
in an x86 folder, and can't consider that lib, because it's compiling for x64. And so you end-up with an unresolved symbol.
Options:
Developer PowerShell for VS 2022
prompt to be x64LIB
environment variableWindows.Clang.toolchain.cmake
to figure out the correct path (stealing/sharing code from/with Windows.MSVC.toolchain.cmake
).
First of all, thank you very much for creating these tool chains. They have been very helpful.
In addition to the windows-msvc-x64 preset, I recently tried out the windows-clangcl-x64 preset in the provided example. Unfortunately it is not working for me in a Developer PowerShell for VS 2022. The windows-msvc-x64 preset works just fine in both a Developer PowerShell for VS 2022 and a x64 Native Tools Command Prompt for VS 2022. However, the windows-clangcl-x64 preset only works in the x64 Native Tools Command Prompt for VS 2022. In the PowerShell I get the error message below. I am not sure I am missing something or whether this is a bug.
Preset CMake variables:
CMAKE_CXX_COMPILER_FRONTEND_VARIANT="MSVC" CMAKE_C_COMPILER_FRONTEND_VARIANT="MSVC" CMAKE_SYSTEM_PROCESSOR="x64" CMAKE_SYSTEM_VERSION="10.0.19041.0" CMAKE_TOOLCHAIN_FILE="../Windows.Clang.toolchain.cmake" CMAKE_VS_VERSION_PRERELEASE="ON" CMAKE_VS_VERSION_RANGE="[16.0,18.0)" CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION_MAXIMUM="10.0.22621.0"
-- The C compiler identification is Clang 17.0.3 with MSVC-like command-line -- The CXX compiler identification is Clang 17.0.3 with MSVC-like command-line -- Detecting C compiler ABI info -- Detecting C compiler ABI info - failed -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/Llvm/x64/bin/clang-cl.exe - broken CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.28/Modules/CMakeTestCCompiler.cmake:67 (message): The C compiler
is not able to compile a simple test program.
It fails with the following output:
CMake will not be able to correctly generate this project. Call Stack (most recent call first): CMakeLists.txt:6 (project)
-- Configuring incomplete, errors occurred!