QMake - Find library names based on kit/target as well as build type - qt-creator

I am trying to link against libraries that are all in the same directory and use the following naming convention:
libFoo64.a # 64-bit release
libFoo32.a # 32-bit release
libFood64.a # 64-bit debug
libFood32.a # 32-bit debug
What can I put in the QMake .pro file so that the right library will be found for each build?
I am using QtCreator 4.9.0 (MSYS2 build) with the default kits enabled:
Desktop Qt MinGW-w64 32-bit (MSYS2)
Desktop Qt MinGW-w64 64-bit (MSYS2)
and for a 32-bit debug build I will choose the 32-bit kit and then the Release configuration under that, etc.
I saw this question which indicates how to set different QMake options for Debug vs. Release but I'm not sure how to extend that to also use different options depending on which Kit is in use.

Based on this question I successfully achieved the goal with the following code in the .pro file:
contains(QT_ARCH, i386) {
CONFIG(debug, debug|release) {
message("32-bit debug")
LIBS += -lFooBard32 -lFooBazd32 -lFooQuxd32 -lFooCorged32 -lFooGraultd32
}else {
message("32-bit release")
LIBS += -lFooBar32 -lFooBaz32 -lFooQux32 -lFooCorge32 -lFooGrault32
}
}else {
CONFIG(debug, debug|release) {
message("64-bit debug")
LIBS += -lFooBard64 -lFooBazd64 -lFooQuxd64 -lFooCorged64 -lFooGraultd64
}else {
message("64-bit release")
LIBS += -lFooBar64 -lFooBaz64 -lFooQux64 -lFooCorge64 -lFooGrault64
}
}
which works although it's not particularly pretty.
I also had to modify my kit configuration so that the 32-bit compiler has 32-bit QT enabled (even though I'm doing a non-QT application , I just use QtCreator because I like the IDE, and I didn't previously have 32-bit QT even installed). The QT_ARCH variable seems to be based on the "Qt Version" configured in the kit, not the actual compiler selected in the kit.

Related

QT Visual studio tools always creates x86 Qt project

I have Qt Creator project. Every time I open the pro file from Qt VS tools, I only get x86 project. In Qt options, I have two compilers, x86 and x64 compiler (default). Even using x64 default compiler produces x86 project.
My project pro file looks like this.
TEMPLATE = app
TARGET = myApp
QT += qml quick core
CONFIG += c++11
HEADERS += main.h
SOURCES += main.cpp
RESOURCES += qml.qrc
# Default rules for deployment.
include(deployment.pri)
INCLUDEPATH += include \
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\windows.h\
MAKE_SPEC = $$split(QMAKESPEC, /)
contains(MAKE_SPEC, msvc2017_64):{
LIBS += -L"$$PWD/lib/x64" -lftd2xx
} else {
LIBS += -L"$$PWD/lib/x86" -lftd2xx
}
DISTFILES += deployment.pri \
lib/ftd2xx.lib \
ui/main.qml
SUBDIRS += myapp.pro
DESTDIR = bin
The platform is selected according to the current default Qt version (Qt VS Tools > Options > Default Qt/Win version). If an x64 Qt build is selected, new projects will be configured with the x64 platform.

Qt project files: win32 or win 64

I am confused about this:
My Qt creator is 32bit while my windows is 64 bit. In .pro file, should I use win 32{...} or win 64 {...}? If I want to link OpenCV libraries, in which one should I use, x64 or x86?
It would be better if you could give me a little explanation about this.
Thanks!
Qmake has some platform and compiler variables like: win32, unix, win32-msvc, ... which are available on mkspecs directory in the installed Qt directory. You can have conditional .pro file based on platform and compiler. For example you can have project which is able to compile both on Windows and Linux. You can linked to an external library conditionally :
win32: LIBS += -L$$PWD/Windows/Path/To/Library/ -lTheLibrary
else:unix: LIBS += -L$$PWD/Linux/Path/To/Library/ -lTheLibrary
If you want to detect whether you are compiling for 32-bit or 64-bit compilers on Windows and linked to relevant libraries accordingly you can use :
win32:contains(QMAKE_HOST.arch, x86_64) {
LIBS += -L$$PWD/Path/To/Library_64Bit/ -lTheLibrary
} else {
LIBS += -L$$PWD/Path/To/Library_32Bit/ -lTheLibrary
}
There are lot of posts that covered these differences, but the important part to remember is that you have to match the architecture between the compiler and the 3rd party libraries that you want to use.
For instance, I have a computer with Windows 64-bit where I use Qt Creator 3.2.1 (opensource) based on Qt 5.3.1 (MSVC 2010, 32 bit). Since my compiler is 32 bit, it's important that I use the 32 bit version of the OpenCV libraries.
So in the .pro file I'll use:
LIBS += -L"C:\\opencv\\build\\x86\\vc12\\lib" \
-lopencv_world300d

Compiling google test framework with Mingw compiler

I have a Qt project and i wanted to use google tests framework GoogleTestFramework in order to do google test. The framework compiled fine on Linux.
I have managed to compile the libraries on windows, using tips provided in the following link:
Installing Gtest without pthreads
The following advice do not let me compile the libraries, because of errors due to pthreads:
Sackoverflow compiling with MSYS
I have :
GNU Make 3.81 for make.exe
GNU Make 3.82 for mingw32-make
CMake 2.8.7
QT 4.7.4
Qt MingW gcc v 4.4.0
When i try to compile my test projet, i get an error saying:
undefined reference to '__chkstk_ms'
File not found: gtest-all.cc
Here is my qmake project code (I have semplified the code).
QT += core gui
DEPENDPATH += . headers src ../FastTrans/headers ../FastTrans/src ../FastTrans/forms C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/include
INCLUDEPATH += . headers src ../FastTrans/headers ../FastTrans/src ../FastTrans/forms C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/include
TARGET = tstall
#CONFIG += console
#CONFIG -= app_bundle
TEMPLATE = app
HEADERS += ../FastTrans/headers/shortcutsactionsitem.h \
../FastTrans/headers/shortcutsactionsmodel.h \
../FastTrans/headers/isavesettings.h
SOURCES += ../FastTrans/src/shortcutsactionsitem.cpp \
../FastTrans/src/shortcutsactionsmodel.cpp \
../FastTrans/src/isavesettings.cpp \
src/tstshortcutsactionsitem.cpp \
src/tstshortcutsactionmodel.cpp
INCLUDEPATH += $$PWD/
DEPENDPATH += $$PWD/
win32: LIBS += C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/mybuid/libgtest.a
win32: LIBS += C:/MinGW/msys/1.0/home/zakharan/gtest-1.6.0/mybuid/libgtest_main.a
Google recommends the following for compiling in Windows:
### Windows Requirements ###
* Microsoft Visual C++ 7.1 or newer
### Cygwin Requirements ###
* Cygwin 1.5.25-14 or newer
I've heard of some people using MingW for compiling this. Supposedly compiling with MingW can be a little faster because there doesn't need to be a comparability layer between the OS and the application.
But, since this is just for dev testing purposes Cygwin should suffice. Just download the version that Google recommends.
See Also:
Compile Cygwin project in Eclipse
How Cygwin compares to MingW for porting Linux applications to Windows

How do I make apps smaller with qmake and macdeployqt

How do I make apps smaller with qmake and macdeployqt?
I have set QT = core gui in the projects .pro file and run qmake and macdeployqt on the resulting app.
The problem is that the program is bundling QtNetwork, QtScript, QtSvg etc. I've tried setting QT -= network script svg (and then make clean, rm -rf *.app, qmake, make).
In total the app is 32 MB.
.pro file:
TEMPLATE = app
TARGET = throw
DEPENDPATH += .
INCLUDEPATH += .
CONFIG += x86_64 release
QT = core gui
unix {
CONFIG += link_pkgconfig
PKGCONFIG += glib-2.0
}
# Input
SOURCES += main.cpp
# Headers
HEADERS += throw.h
RESOURCES += throw.qrc
ICON = throw.png
mac {
QMAKE_INFO_PLIST = Info.plist
ICON = throw.icns
}
This is a great article about (re)building Qt statically and dynamically to reduce its size considerably: Building Qt Static (and Dynamic) and Making it Small with GCC, Microsoft Visual Studio, and the Intel Compiler
While this is talking about Qt in the windows context, it does give some good insight into how one would go about compiling for minimal size.
You could strip the binary afterwards in a post-build step. The Qt libraries themselves are shared by default.

How can I force qtcreator to create non-universal binaries

When I use qtcreator on mac, it creates universal binaries.
Does anyone know how to set it so it just creates a 'native' binary? (So i386' in my case?)
Qtcreator uses qmake as a buildsystem.
Google hasn't been my friend so far, I hope stackoverflow will.
EDIT:
my config file so far:
TARGET = mongowriter
CONFIG += console
CONFIG -= app_bundle
CONFIG += x86
#CONFIG -= ppc
TEMPLATE = app
INCLUDEPATH += /opt/local/include/.
INCLUDEPATH += ../mongodb/.
SOURCES += main.cpp
LIBS += /usr/local/lib/libmongoclient.a
LIBS += /opt/local/lib/libboost_thread-mt.a
LIBS += /opt/local/lib/libboost_filesystem.a
LIBS += /opt/local/lib/libboost_program_options.a
It still gives the error on the libmongoclient.a
The libboost libraries are all ok, but this is because I got them from macports with the +universal option.
Since mongoclient doesn't support universal I'm currently removing all the universal stuff. I was hoping to get 3 errors for the boost libs and that at l;east mongoclient would link.
At that point I could redo the whole macport story again but this time with universal removed.
Unfortunately it seems it still builds a universal binary since I still have the same linker errors.
thanks for the help
you can use the 'CONFIG' variable in your project file to specify which plattforms shall be supported to create a universial binary you use
CONFIG += x86 ppc
if you only need x86 you use
CONFIG += x86

Resources