How can I force QtCreator to use clang/llvm instead of gcc
-
wrote 9 days ago last edited by
I'm having problems with some of the newer aspects of C++23. I'm actually trying to foillow a course but am getting compile or runtime errors. The instructor uses VS Code on Windows and the cl compiler - which seems to be more up-to-date than gcc. Anyway, I installed Code on my Linux box and llvm 19.1 . I also installed GCC 14.2 using homebrew as this version was not available from the Ubuntu repo. (It is available if you install Ubuntu 25.04 though?)
When I follow the instructions using VS Code, I can choose which compiler to use. It's a simple dropdown menu on the comfigure page and I want to know how I can choose the compiler in QtCreator.
I have been through all the kit selection menus and compiler selection options but nothing works. When I look at the compiler output, it is still using gcc and is thus failing to compile some code.
Everything (so far) works fine until I try to use modules or a vcpkg. Sometimes it works, most times not and the error messages are not helpful at all. There are no errors in the code as it compiles perfectly using llvm from the Code IDE.
The only conclusion I can come to is that GCC 14.2 does not fully support C++23, whereas llvm 19.1 supports more.
I know GCC 15.1 is out now but It isn't available from homebrew yet so short of building it myself, I cannot use it.
I also tried the failing code in CLion and Eclipse but they default to using GCC and so I get the same problems.
Someone replied to an earlier similar post that I should just use Code for the course. I am having to do that but I would like to know how to specify the compiler in QtCreator as that is my preferred IDE.
I'm using CMake 3.31.6.
Colin -
I'm having problems with some of the newer aspects of C++23. I'm actually trying to foillow a course but am getting compile or runtime errors. The instructor uses VS Code on Windows and the cl compiler - which seems to be more up-to-date than gcc. Anyway, I installed Code on my Linux box and llvm 19.1 . I also installed GCC 14.2 using homebrew as this version was not available from the Ubuntu repo. (It is available if you install Ubuntu 25.04 though?)
When I follow the instructions using VS Code, I can choose which compiler to use. It's a simple dropdown menu on the comfigure page and I want to know how I can choose the compiler in QtCreator.
I have been through all the kit selection menus and compiler selection options but nothing works. When I look at the compiler output, it is still using gcc and is thus failing to compile some code.
Everything (so far) works fine until I try to use modules or a vcpkg. Sometimes it works, most times not and the error messages are not helpful at all. There are no errors in the code as it compiles perfectly using llvm from the Code IDE.
The only conclusion I can come to is that GCC 14.2 does not fully support C++23, whereas llvm 19.1 supports more.
I know GCC 15.1 is out now but It isn't available from homebrew yet so short of building it myself, I cannot use it.
I also tried the failing code in CLion and Eclipse but they default to using GCC and so I get the same problems.
Someone replied to an earlier similar post that I should just use Code for the course. I am having to do that but I would like to know how to specify the compiler in QtCreator as that is my preferred IDE.
I'm using CMake 3.31.6.
Colin@Colins2 said in How can I force QtCreator to use clang/llvm instead of gcc:
I have been through all the kit selection menus and compiler selection options but nothing works
First add the compiler on the compiler tab, then create a Kit and select that compiler. Then select the new Kit for your project. This should work. If it does not work then tell us what happens.
-
@Colins2 said in How can I force QtCreator to use clang/llvm instead of gcc:
I have been through all the kit selection menus and compiler selection options but nothing works
First add the compiler on the compiler tab, then create a Kit and select that compiler. Then select the new Kit for your project. This should work. If it does not work then tell us what happens.
wrote 9 days ago last edited by Colins2 5 Sept 2025, 13:51@jsulm That is what I have been trying to do, so far without any success.
My system, Linux Mint 22.1, comes with GCC 13.1 with no update available. (yet)
I added GCC 14.1 via Homebrew and did as you said above but it didn't work, Qt continued to use GCC 13.1
In the end, I used 'sudo update-alternative' to get /bin/gcc to use the homebrew gcc.
That works up to a point but even 14.1 won't compile (consistently) any code with modules or vcpkg.
I do get some errors using Code as well but usually deleting the build folder and re-configuring does the trick. That doesn't work with QtCreator. It is not reproducible, sometimes it will compile, other times it just throws stupid errors like 'cant find utilities.ixx, even though it found it on a previous build.
I don't have these problems using Code with Clang 19.1, which is why I want to set it as the default compiler, or, at least, be able to select it for a project.
These are not complex programs I am writing, just basically 'hello worlds' expanded to use modules and print different things from different places, so that I can get a better idea of what is happening.
The vcpkg problem comes when I try to use the fmt library. Again, it works perfectly with Clang. As a plus, GCC14.1 does support std::format and std::print that do the same job as the fmt package!
I'm using Qt Creator 16.0.1 / Qt 6.8.3 built on April 10 2025 -
wrote 9 days ago last edited by Colins2 5 Sept 2025, 14:49
Solved!
Here are the steps I had to take.
I opened a default non-qt app and just accepted the defaults for the rest. That gets me a basic 'hello world' app that compiles and runs using GCC-14. (after previous steps).
I went to kits and accepted the only entry for Desktop Qt. then I went to the compilers tab and removed the GCC entries, leaving just clang and a custom compiler that pointed to the Homebrew download of GCC-14. I couldn't see anything else relevant on the other tabs.
That wouldn't compile and I got errors about not finding a CXX compiler even though clang is in my path and before GCC.
I added the line 'export $CXX=/usr/bin/clang++ to my .bashrc and re-started the terminal. I checked the $CXX variable and it showed as /usr/bin/clang++. It still would not find clang++.
Lastly, I found I had to add the line 'set(CMAKE_CXX_COMPILER clang++)' to the CMakeLists.txt before the
'project(helloClang LANGUAGES CXX)' line. I tried putting the path in but CMake didn't like that!
Finally, it compiled using clang! I have yet to try using modules or the vcpkg::fmt library but they both worked using Code, so I am hopeful they will work here as well.
What a palaver, just to change compiler! -
-
wrote 8 days ago last edited by
Just an addendum to this post:
I closed Qt Creator after the above post. When I opened it again today to test the module functions, Qt tried to revert everything to GCC. The kits I had removed had come back, the default compiler was set to /usr/bin/gcc and every time I edited a file I got a dialog box asking if I wished to change back to GCC. I had to go into the build settings and manually edit the compiler line and set it back to clang and then the dialog went away.
Am I really going to have to do this every time I want to use clang?
Hopefully, GCC15.1 will be available soon on Homebrew and it will recognize modules and vcpkg packages properly!
1/5