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
-
It is not sufficient to enable modules for the compiler. Your build system (CMake in this case) needs to now about modules as well to compute the right dependencies. You have to tell CMake which files are defining modules (maybe have a look here: https://cryos.net/2024/01/c-modules-and-cmake/). Otherwise your build might fail (it also might just work right most of the time if the dependencies are accidentally compiled in the right order). If I'm not mistaken modules with CMake so far only work with the ninja generator.
The reason why the build system needs to know about that is because if the compiler is looking for a module and it hasn't been compiled yet, there is no way for the compiler to tell the build system to just build the necessary module. So, the build system has to make sure that all modules have been built (in the right order) before regular compilation starts. (It would be certainly nice if the compiler could just compile the required module as well and then continue. But this is not how it works.)