Adding different compiler to QT - c++

How can I add another compiler and use it with QT?
I'm asking because I couldn't find it anywhere on the web how to do it.
Thanks.

If you are using qmake, you can override the compiler used by the current mkspec with QMAKE_CXX, e.g. qmake QMAKE_CXX=g++-4.6.
To permanently override it, you'll need a new or edit the mkspec files. You can browse where they are with qmake -query and look at the QMAKE_MKSPECS variable. From there, the directory "default" is used if you do not use the -spec parameter in qmake. In that directory, the file qmake.conf will contain the mentioned QMAKE_CXX paramater that determines the compiler.

On MacOs, if you want to use gcc/g++ you can edit the Project (.pro) file to include (at the top):
QMAKE_CC = gcc
QMAKE_CXX = g++
Then run qmake against the Project file.

Related

How to use clang 5 with qt in qt creator?

I've configured my locally installed version of clang 5.
and set up a kit with it
but when I do a build with it:
it's clearly still using the system compiler for qmake, which causes a bunch of errors because my code requires C++17 support:
How do I set what compiler qmake is using?
Thank you.
You can do it in your pro file, directly:
QMAKE_CC = /path/to/the/c/compiler
QMAKE_CXX = /path/to/the/c++/compiler
but you'd be better specify the correct Qt mkspec in your kit, which could be something like linux-clang. Check the mkspecs directory, see if in some of its subdirectories there is the right qmake.conf already, if not you can make a new subdirectory in mkspecs and a new configuration file inside it. The mkspecs directory should be in the path given by the terminal command
qmake -query QT_INSTALL_ARCHDATA
Hope it helped.

How to prohibit Qt Creator to use specific include path automatically?

I use 2 different GCC versions on the same CentOS machine (included in OS one and custom one), and I don't want to replace system GCC with my custom one, I use custom one to build some software only.
The problem is that Qt Creator adds /usr/include to include folders automatically, so custom GCC starts to use system C++ includes and crashes with strange error messages like error: '::memchr' has not been declared. I don't have /usr/include anywhere in my *.pro file, so it looks like Qt Creator adds them itself.
How to prohibit Qt Creator project to use some specific include patches to allow compilation on machine with 2 GCC versions? When I use Eclipse CDT on the same machine, it works excellently, because Eclipse doesn't add anything itself and only uses include directories specified by me.
You can use CXXFLAGS += -nostdinc.
This should do the following (excerpt from the manual):
Do not search the standard system directories for header files. Only the directories you have specified
with -I options (and the directory of the current file, if appropriate) are searched.
It is not elegant answer, if someone has better ideas, you are still welcome to post your answer and I'll accept it.
So, I added custom build step between qmake and make commands, and I use sed command in this custom build step to edit Makefile on the fly and remove extra includes. This solution works, however, it is ugly.

How configure Qt Creator to compile qupzilla?

Is there any simple way to configure Qt Creator to compile qupzilla in my folder (not in /usr/bin and /usr/lib)?
By default i get "error: ../../bin/libQupZilla.so". If i set the path to my app folder with ldconfig - app is compiled but without plugins. They return errors for example (build/qrc_testplugin.cpp Error 1 or something with locale folder).
OS: Arch Linux 64 bit
QT: Qt5
Also i successfully compile qupzilla-git from AUR with qt5. This means that my problem somewhere in incorrect settings or paths...
Qupzilla: http://www.qupzilla.com/
Solution:
1) Add path to programm "path_to_app/bin" to ldconfig (/etc/ld.so.conf)
2) Check off in Projects "Shadow build" checkbox.
3) Change qmake to qmake-qt5. If I understand correctly, it is not necessary to do. Since in Arch Linux qmake and qmake-qt5 same.
4) In build environment add
KDE true
USE_WEBGL true
If you have libQupZilla (or any library) somewhere else than system library directories, easiest is to edit the .pro file, add line like:
LIBS += -L$(PWD)/..relative-path-to-library-location../
...or use absolute path to the library if you want. You probably already have -lQupZilla there, so no need to add that the 2nd time.
In general, with problems like this in Qt Creator, look at the Compile Output tab (at the bottom of the screen). Find the link command (note: if project uses cmake instead of qmake, you may need to add some switches or something for that to make the command visible), which is the one with all the -L/path and -lfoobar switches, and -o programname outputting the final target. Then look earlier to see in what directory it is being run in. Then look if everything matches, and possibly try to copy-paste and run the command from command line yourself, in the same directory where it is run when building under Qt Creator.

Qt unit-test: why "qmake" is not recognized

I managed to follow this tutorial in order to write my first unit-test.
However, when opening a "cmd-console" from inside my project folder and try to rum qmake, i get the following error:
'qmake' is not recognized as an internal or external command, operable program or batch file.
so, why qmake is not recognized? (note that I am working on windows Vita)
On Windows qt and its tools are installed by default in C:\Qt\blablah. You should add the path to the qmake binary, and that will do the trick. See the instructions here. Note that Qt creator set some variables for its terminal so you use qmake in creator without touching the system.
set path the Qt compiler.
sth like this:
set PATH=C:\Qt\4.8.5\bin
where the 4.8.5 is the version of Qt you installed.
If you don't want to add the QT bin path to PATH you can write the full path to qmake:
>"$(QTDIR)\bin\qmake.exe" -o Makefile odbc.pro
where $(QTDIR) is the full path of the qtbase directory.

How to get qmake to generate "project dependencies" in a Visual Studio .sln project

I have a qmake build of a few libraries and an app which depends on them. Using the subdirs template I'm able to get qmake to output a .sln file which works almost to my liking in VC2008. Though I've specified the dependencies between the targets in every way I've seen described, I end up with no "project dependencies" in the .sln file, and I have to add these in manually.
So far I've tried
CONFIG += ordered
with correct ordering to no avail.
And similarly the more arcane syntax:
client.depends = core common
Which also doesn't work. No dependencies whatsoever show up when I load the sln.
Both CONFIG += ordered and target.depends = are not supported by the qmake's MSVC backend (solution generator). Back in 2010 with Qt 4.7 around, the docs didn't mention that, but in Qt 4.8 the developers have updated the docs accordingly (see the Target section remarks):
.depends This subproject depends on specified subproject. Available only on platforms that use makefiles.
The ordered option is not supported for Visual Studio.
But they had provided a workaround (which is discussed in that cryptic post), and it's still valid and even documented in the same target section. Too bad I had to rebuild qmake and use a debugger to verify that:
a) There is a Lib/DLL project of which TARGET (the .lib is used and not the .dll) is used on the link line of another project in your solution (you can modify the link line with LIBS).
b) There is an Exe project of which TARGET is used in a custom build-step of another project in your solution.
You don't use paths in the TARGET variable (use DESTDIR/DLLDESTDIR for that), e.g, TARGET=$(SOME_VARIABLE)/myLib, won't work.
If you have a special location for your libs, you specify the -Lmy/library/path and LIBS += mylib, instead of just using LIBS += my/library/path/mylib
The leaf projects are created before you generate the solution file. (You can use the recursive flag for qmake to do this, like "qmake -tp vc -r [yourproject.pro]"
Basically, qmake will generate dependency when your lib's target name (yourlib.lib) is equal to the one of the import libraries of the final app (that has LIBS += yourlib.lib).
(See qmake's source where the import libraries are added as dependencies, and a little further where they're compared with the project target names)
Here is the minimal setup that generates dependencies in the solution:
solution.pro
TEMPLATE = vcsubdirs
SUBDIRS = main app
app/app.pro
LIBS += main.lib
main/main.pro
TARGET = main
TEMPLATE = vclib
With those, if you run qmake -r -tp vc, you'll get the explicit dependency in the generated .sln:
GlobalSection(ProjectDependencies) = postSolution
{E634D0EB-B004-3246-AADA-E383A376158F}.0 = {1BD6E999-63E6-36F5-99EE-1A650332198C}
EndGlobalSection
From an old mailing list entry:
http://lists.trolltech.com/qt-interest/2006-07/thread00238-0.html
It appears that it tries to figure out which things are dependent for you. Are you able to build from the sln without entering the project dependencies manually?
I am not a wiz in makefiles but if I were you, I would try to recreate that dependency in with QtCreator by editing the .pro file, running qmake then looking at the auto-generated result in the MAKLEFILE. If you want to know how qmake works then look at the qt documentation.