Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to configure QtCreator to use Clang 19 instead of GCC

How to configure QtCreator to use Clang 19 instead of GCC

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
7 Posts 4 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pete Carter
    wrote on 31 Dec 2024, 21:54 last edited by Pete Carter
    #1

    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 Clang

    I downloaded Clang v19:

    sudo apt install clang-19 clangd-19 clang-format-19 clang-tidy-19 clang-tools-19
    

    Screenshot_20250101_004617.png


    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/cmake

    everything else is the same as GCC kit

    Screenshot_20250101_004223.png


    In Preferences -> C++ -> Clangd

    Path to executable: /usr/bin/clangd-19

    Screenshot_20250101_004305.png


    In Preferences -> Analyzer -> Clang Tools

    Clang-Tidy: /usr/bin/clang-tidy-19

    Screenshot_20250101_004524.png


    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

    Screenshot_20250101_004923.png

    J 1 Reply Last reply 2 Jan 2025, 06:35
    0
    • P Offline
      P Offline
      Pete Carter
      wrote on 1 Jan 2025, 00:15 last edited by
      #2

      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
      

      Screenshot_20250101_031343.png

      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 ?

      1 Reply Last reply
      0
      • P Pete Carter
        31 Dec 2024, 21:54

        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 Clang

        I downloaded Clang v19:

        sudo apt install clang-19 clangd-19 clang-format-19 clang-tidy-19 clang-tools-19
        

        Screenshot_20250101_004617.png


        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/cmake

        everything else is the same as GCC kit

        Screenshot_20250101_004223.png


        In Preferences -> C++ -> Clangd

        Path to executable: /usr/bin/clangd-19

        Screenshot_20250101_004305.png


        In Preferences -> Analyzer -> Clang Tools

        Clang-Tidy: /usr/bin/clang-tidy-19

        Screenshot_20250101_004524.png


        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

        Screenshot_20250101_004923.png

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 2 Jan 2025, 06:35 last edited by
        #3

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 1 Reply Last reply 2 Jan 2025, 07:21
        0
        • J jsulm
          2 Jan 2025, 06:35

          @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.

          P Offline
          P Offline
          Pete Carter
          wrote on 2 Jan 2025, 07:21 last edited by
          #4

          @jsulm

          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.txt

          cmake_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:

          Screenshot_20250102_101744.png

          main.cpp:4:10: 'bitset' file not found
          

          The toolchain supposed to be in /usr/lib/llvm-19/

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cristian-adam
            wrote on 2 Jan 2025, 10:36 last edited by
            #5

            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/1293

            It looks like progress is being made though.

            P 1 Reply Last reply 2 Jan 2025, 11:34
            1
            • C cristian-adam
              2 Jan 2025, 10:36

              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/1293

              It looks like progress is being made though.

              P Offline
              P Offline
              Pete Carter
              wrote on 2 Jan 2025, 11:34 last edited by
              #6

              @cristian-adam

              Thanks man

              1 Reply Last reply
              1
              • S Offline
                S Offline
                SimonSchroeder
                wrote on 9 Jan 2025, 08:10 last edited by
                #7

                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.)

                1 Reply Last reply
                1

                6/7

                2 Jan 2025, 11:34

                • Login

                • Login or register to search.
                6 out of 7
                • First post
                  6/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved