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

Hugo Melder hugo at algoriddim.com
Mon Nov 25 15:20:08 CET 2024


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/20241125/dd594296/attachment-0001.htm>


More information about the Qt-creator mailing list