[Qt-creator] [Qt Creator] Windows Kit libraries not picked up in Clang (GNU-like command-line) Configuration

Cristian Adam cristian.adam at qt.io
Fri Nov 29 13:53:14 CET 2024


Hi,

Surely. You would have to use a CMakePresets.json file and tweak some version numbers / paths. It's a bit verbose, but it's the only way you can get this working with Qt Creator at the moment.

{
  "version": 4,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 23,
    "patch": 0
  },
  "configurePresets": [
    {
      "name": "clang-ninja",
      "displayName": "Clang x64 Ninja",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build-${presetName}",
      "toolchainFile" : "c:/Qt/6.8.0/msvc2022_64/lib/cmake/Qt6/qt.toolchain.cmake",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_CXX_COMPILER" : "clang++.exe",
        "CMAKE_C_COMPILER": "clang.exe"
      },
      "environment" : {
        "VCToolsVersion": "14.42.34433",
        "WindowsSDKVersion" : "10.0.22621.0",
        "VCArch": "x64",
        "VCToolsInstallDir": "$env{ProgramFiles(x86)}/Microsoft Visual Studio/2022/BuildTools/VC/Tools/MSVC/$env{VCToolsVersion}",
        "WindowsSdkDir" : "$env{ProgramFiles(x86)}/Windows Kits/10",
        "WindowsSdkIncVerDir": "$env{WindowsSdkDir}/Include/$env{WindowsSDKVersion}",
        "WindowsSdkLibVerDir": "$env{WindowsSdkDir}/Lib/$env{WindowsSDKVersion}",

        "INCLUDE": "$env{VCToolsInstallDir}/ATLMFC/include;$env{VCToolsInstallDir}/include;$env{WindowsSdkIncVerDir}/ucrt;$env{WindowsSdkIncVerDir}/shared;$env{WindowsSdkIncVerDir}/um;$env{WindowsSdkIncVerDir}/winrt;$env{WindowsSdkIncVerDir}/cppwinrt",
        "LIB": "$env{VCToolsInstallDir}/ATLMFC/lib/$env{VCArch};$env{VCToolsInstallDir}/lib/$env{VCArch};$env{WindowsSdkLibVerDir}/ucrt/$env{VCArch};$env{WindowsSdkLibVerDir}/um/$env{VCArch}",
        "PATH": "$env{ProgramFiles}/LLVM/bin;$env{VCToolsInstallDir}/bin/HostX64/$env{VCArch};$env{WindowsSdkDir}/bin/$env{WindowsSDKVersion}/$env{VCArch};$penv{PATH}"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "clang-ninja",
      "configurePreset": "clang-ninja"
    }
  ]
}

The result looks like this:

[cmake] Running C:\Program Files\CMake\bin\cmake.exe -S C:/Projects/Hello🌍 -B C:/Projects/Hello🌍/build-clang-ninja "-DCMAKE_C_COMPILER:FILEPATH=C:/Program Files/LLVM/bin/clang.exe" "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=C:\Projects\Hello🌍\build-clang-ninja/.qtc/package-manager/auto-setup.cmake" "-DCMAKE_CXX_FLAGS_INIT:STRING=" "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.8.0/msvc2022_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.8.0/msvc2022_64" "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=c:/Qt/6.8.0/msvc2022_64/lib/cmake/Qt6/qt.toolchain.cmake" "-DCMAKE_BUILD_TYPE:STRING=Release" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/Program Files/LLVM/bin/clang++.exe" in C:\Projects\Hello🌍\build-clang-ninja.
[cmake] -- The C compiler identification is Clang 19.1.4 with GNU-like command-line
[cmake] -- The CXX compiler identification is Clang 19.1.4 with GNU-like command-line
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/Program Files/LLVM/bin/clang.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Clang
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
[cmake] -- Check if compiler accepts -pthread
[cmake] -- Check if compiler accepts -pthread - no
[cmake] -- Looking for pthread_create in pthreads
[cmake] -- Looking for pthread_create in pthreads - not found
[cmake] -- Looking for pthread_create in pthread
[cmake] -- Looking for pthread_create in pthread - not found
[cmake] -- Found Threads: TRUE
[cmake] -- Performing Test HAVE_STDATOMIC
[cmake] -- Performing Test HAVE_STDATOMIC - Success
[cmake] -- Found WrapAtomic: TRUE
[cmake] -- Configuring done (3.9s)
[cmake] -- Generating done (0.0s)
[cmake] -- Build files have been written to: C:/Projects/Hello🌍/build-clang-ninja

Cheers,
Cristian
________________________________
From: Qt-creator <qt-creator-bounces at qt-project.org> on behalf of Hugo Melder via Qt-creator <qt-creator at qt-project.org>
Sent: Monday, November 25, 2024 15:20
To: qt-creator at qt-project.org <qt-creator at qt-project.org>
Subject: [Qt-creator] [Qt Creator] Windows Kit libraries not picked up in Clang (GNU-like command-line) Configuration

Hi,

We are currently integrating address sanitisation in out build system, which requires using clang.exe/clang++.exe instead of clang-cl.exe (see https://gitlab.kitware.com/cmake/cmake/-/issues/26430#note_1590998).
However, when configuring a “Kit” in QTC with clang.exe, the libraries from the Windows Kit (C:\Program Files (x86)\Windows Kits\10\Lib\10.0.22000.0\um\x64) are no longer added to the library path. I assume that
QTC does not initialise the environment correctly, because it works perfectly fine in a VS Dev prompt.

Here is an example project that demonstrates this.


cmake_minimum_required(VERSION 3.16)

project(testProj VERSION 1.0.0 LANGUAGES C CXX)

message(STATUS ${CMAKE_C_COMPILER_ID})

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS Core)
find_library(LIB_advapi32 advapi32 REQUIRED)
qt_standard_project_setup()


qt_add_executable(testProj main.cpp)
target_link_libraries(testProj PRIVATE Qt6::Core)

Qt Creator 14.0.1 Enterprise

[cmake] Running C:\x86_64-pc-windows\CMake\bin\cmake.exe -S C:/Users/hugo/Documents/QtProject -B C:/Users/hugo/Documents/QtProject/build/Desktop_Qt_6_8_0_Clang_GNU_like-Debug "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.8.0/msvc2022_64/bin/qmake.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/x86_64-pc-windows/LLVM/bin/clang++.exe" "-DCMAKE_C_COMPILER:FILEPATH=C:/x86_64-pc-windows/LLVM/bin/clang.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.8.0/msvc2022_64" "-DCMAKE_CXX_FLAGS_INIT:STRING=-DQT_QML_DEBUG" "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=C:\Users\hugo\Documents\QtProject\build\Desktop_Qt_6_8_0_Clang_GNU_like-Debug/.qtc/package-manager/auto-setup.cmake" in C:\Users\hugo\Documents\QtProject\build\Desktop_Qt_6_8_0_Clang_GNU_like-Debug.
[cmake] -- The C compiler identification is Clang 19.1.3 with GNU-like command-line
[cmake] -- The CXX compiler identification is Clang 19.1.3 with GNU-like command-line
[cmake] -- Detecting C compiler ABI info
[cmake] -- Detecting C compiler ABI info - done
[cmake] -- Check for working C compiler: C:/x86_64-pc-windows/LLVM/bin/clang.exe - skipped
[cmake] -- Detecting C compile features
[cmake] -- Detecting C compile features - done
[cmake] -- Detecting CXX compiler ABI info
[cmake] -- Detecting CXX compiler ABI info - done
[cmake] -- Check for working CXX compiler: C:/x86_64-pc-windows/LLVM/bin/clang++.exe - skipped
[cmake] -- Detecting CXX compile features
[cmake] -- Detecting CXX compile features - done
[cmake] -- Clang
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD
[cmake] -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
[cmake] -- Check if compiler accepts -pthread
[cmake] -- Check if compiler accepts -pthread - no
[cmake] -- Looking for pthread_create in pthreads
[cmake] -- Looking for pthread_create in pthreads - not found
[cmake] -- Looking for pthread_create in pthread
[cmake] -- Looking for pthread_create in pthread - not found
[cmake] -- Found Threads: TRUE
[cmake] -- Performing Test HAVE_STDATOMIC
[cmake] -- Performing Test HAVE_STDATOMIC - Success
[cmake] -- Found WrapAtomic: TRUE
[cmake] CMake Error at CMakeLists.txt:11 (find_library):
[cmake]   Could not find LIB_advapi32 using the following names: advapi32
[cmake]
[cmake]
[cmake] -- Configuring incomplete, errors occurred!
[cmake]
[cmake] The command "C:\x86_64-pc-windows\CMake\bin\cmake.exe -S C:/Users/hugo/Documents/QtProject -B C:/Users/hugo/Documents/QtProject/build/Desktop_Qt_6_8_0_Clang_GNU_like-Debug "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.8.0/msvc2022_64/bin/qmake.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/x86_64-pc-windows/LLVM/bin/clang++.exe" "-DCMAKE_C_COMPILER:FILEPATH=C:/x86_64-pc-windows/LLVM/bin/clang.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.8.0/msvc2022_64" "-DCMAKE_CXX_FLAGS_INIT:STRING=-DQT_QML_DEBUG" "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=C:\Users\hugo\Documents\QtProject\build\Desktop_Qt_6_8_0_Clang_GNU_like-Debug/.qtc/package-manager/auto-setup.cmake"" terminated with exit code 1.
[cmake]
[cmake] Elapsed time: 00:07.

Inside an x64 Visual Studio 2022 Developer Command Prompt v17.10.0-pre.3.0

C:\Users\hugo\Documents\QtProject>echo %VSCMD_ARG_TGT_ARCH%
x64

C:\Users\hugo>clang --version
clang version 19.1.3
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\x86_64-pc-windows\LLVM\bin

C:\Users\hugo\Documents\QtProject>cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_PREFIX_PATH="C:\Qt\6.8.0\msvc2022_64" -B build -G Ninja
-- The C compiler identification is Clang 19.1.3 with GNU-like command-line
-- The CXX compiler identification is Clang 19.1.3 with GNU-like command-line
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/x86_64-pc-windows/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:/x86_64-pc-windows/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Clang
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - no
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Configuring done (5.9s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Users/hugo/Documents/QtProject/build


Is it generally possible in QTC to use clang (GNU-like command-like) with a VS environment? I really do not like the “magic” going on in QTC’s build configuration.

~ Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20241129/d0d371b9/attachment-0001.htm>


More information about the Qt-creator mailing list