How to configure QtCreator to use Clang 19 instead of GCC
-
I have been trying to use the modules feature is C++ but somehow there is a problem in GCC (12.2.0)
Since i could not update GCC, i decided to switch to ClangI downloaded Clang v19:
sudo apt install clang-19 clangd-19 clang-format-19 clang-tidy-19 clang-tools-19
In QtCreator, Preferences -> Kits
I cloned the Desktop GCC kit, then modified the following:Compiler: /bin/clang-19
Debugger: /usr/bin/lldb-19
CMake Tool: /usr/bin/cmakeeverything else is the same as GCC kit
In Preferences -> C++ -> Clangd
Path to executable: /usr/bin/clangd-19
In Preferences -> Analyzer -> Clang Tools
Clang-Tidy: /usr/bin/clang-tidy-19
Now everything should be configured correctly, that's what i thought ...
I have a problems i noticed so far, I cannot find any files i include, like iostream or cassert
-
Tried adding the libraries in the include path in CMakeLists.txt
cmake_minimum_required(VERSION 3.25) project(learn_cpp_33 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_compile_options(-fmodules-ts) add_executable(learn_cpp_33 src/main.cpp src/lib/helpers.cpp src/lib/data.cpp) target_include_directories( learn_cpp_33 SYSTEM PRIVATE /usr/lib/llvm-19/include /usr/lib/llvm-19/include/c++/v1) include(GNUInstallDirs) install( TARGETS learn_cpp_33 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
But now i am getting a different error:
main.cpp:1:10: In included file: 'features.h' file not found platform.h:35:12: error occurred here
I also don't want to keep editing the cmake file like that for every project, is there a way to add this include path system wide so that qtcreator can find it automatically ?
-
@Pete-Carter said in How to configure QtCreator to use Clang 19 instead of GCC:
I have a problems i noticed so far, I cannot find any files i include, like iostream or cassert
Does the project compile?
These errors you show could come from the code model. -
When i restarted the IDE, and changed the kit to clang, it now compiles.
it compiles well without trying to use modules.
However when i try to add modules support by adding
add_compile_options(-fmodules-ts)
in CMakeLists.txtcmake_minimum_required(VERSION 3.16) project(learn_cpp_7 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_compile_options(-fmodules-ts) add_executable(learn_cpp_7 src/main.cpp src/lib/helpers.hpp src/lib/helpers.cpp src/lib/data.hpp src/lib/data.cpp src/module_0.cpp) include(GNUInstallDirs) install( TARGETS learn_cpp_7 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
I get this error:
main.cpp:4:10: 'bitset' file not found
The toolchain supposed to be in
/usr/lib/llvm-19/
-
The issue is tracked at https://bugreports.qt.io/browse/QTCREATORBUG-28465
clangd
doesn't currently support C++20's modules. See also https://github.com/clangd/clangd/issues/1293It looks like progress is being made though.
-
Thanks man