Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build Qt with custom compiler and custom flags?

Tags:

c++

qt

I am building Qt 5.4 and I want to use my custom built GCC version which is different from the system one. I don't want to replace system GCC with my one. However, I don't see how can I alter the compiler absolute path that the Qt build system uses, as well as how to add custom flags. Usually open source libraries use CXX and CXXFLAGS variables to alter compiler absolute path and its options, but it looks like Qt build system ignores these variables.

Does Qt 5.4 build system have any options similar to common for GNU projects CXX and CXXFLAGS, as well as LD and LDFLAGS?

like image 550
Vitalii Avatar asked Feb 10 '15 15:02

Vitalii


People also ask

How do I add a compiler to QT?

To add a C or C++ compiler, select Edit > Preferences > Kits > Compilers > Add. Select a compiler in the list, and then select C or C++.

What compiler does Qt Creator use?

Qt Creator uses the C++ compiler from the GNU Compiler Collection on Linux. On Windows it can use MinGW or MSVC with the default install and can also use Microsoft Console Debugger when compiled from source code. Clang is also supported.


1 Answers

As @BartoszKP adviced, it is required to make custom build platform. Easier (but less elegant and less "educational") idea is to modify existing platform. I used linux-g++ platform as a base. This platform qmake.conf file path relative to source code directory is qtbase/mkspecs/linux-g++/qmake.conf. I added following lines at the very bottom of this file:

QMAKE_CXX               = /path/to/custom/g++
QMAKE_LINK              = /path/to/custom/g++
QMAKE_LFLAGS            += -custom-link-flags-here
QMAKE_CC                = /path/to/custom/gcc
QMAKE_LINK_C            = /path/to/custom/gcc

Now Qt build platform uses my custom compiler instead of existing system one, and it adds my custom linker flags.

like image 193
Vitalii Avatar answered Sep 27 '22 16:09

Vitalii