QtCreator normally defines ABI, but it’s better to double-check. You can also notice that the system x64 GCC in Linux can also generate 32-bit applications. However, this does not eliminate the fact that 32-bit versions of libraries are also needed.
You can add Qt profiles after compilers:
The previously collected qmake, uic, moc, rcc will be useful when adding a profile. You need to select a directory with qmake. A yellow icon with an exclamation mark to the left of the profile indicates a warning, but QtCreator can use such a Qt profile. But if the icon is red, then the profile is non-working. This can happen with an incorrect directory structure. Or if you delete the directory in which Qt was compiled.
The following settings need to be done for each created project. You must go to the “Projects” tab (Ctrl+5) when the project is active. Then add a specific Qt profile:
By default, only the Qt system profile is listed in the “Modify Assembly Configuration” list. But there are all Qt profiles in the list of the “Add” button.
You need to check the library-compiler pair in the main assembly settings. So that both of them were from the same operating system.
QtCreator defaults to the build steps “qmake” and “Build”. I manually added the special stages “upx” and “dmgbuild” for my project. The “upx” stage is executed every time you click the “Build project” button. However, if the executable file has not been modified then upx will return an error. It means that the file has already been processed. In the error triggered, the next step will not be called, i.e. the dmg file will only be updated if upx has worked.
“Upx” tool must be installed on the system for the “upx” stage to work. However, even working in Linux-environment upx can compress applications for: linux32/64, win32, macos32/64. Upx-compression is really needed not for all projects; the stage is shown rather for an example.
For the “dmgbuild” stage, I used the make_dmg script. It needs root privileges so you need to add the script to the /etc/sudoers file.
My project uses libusb, this is not part of Qt. It was also necessary to include a platform-dependent implementation of the HID. The following lines were added to the project file:
macx {
INCLUDEPATH += $$PWD/libusbx/
SOURCES += BootLoader/HIDAPI/mac/hid.c
LIBS += -framework IOKit -framework CoreFoundation -lusb-1.0
ICON = AqPicFlash.icns
}
win32: {
INCLUDEPATH += $$PWD/libusbx/
LIBS += -lsetupapi -lole32
SOURCES += BootLoader/HIDAPI/windows/hid.cpp
RC_FILE = WinIcon.rc
}
win32: !win64-x-g++ {
LIBS += -L$$PWD/libusbx/ -lusb-1.0-32.dll
}
win64-x-g++ {
LIBS += -L$$PWD/libusbx/ -lusb-1.0-64.dll
}
unix: !macx {
CONFIG += link_pkgconfig
PKGCONFIG += libusb-1.0
SOURCES += BootLoader/HIDAPI/linux/hid-libusb.c
}
We link to the system libusb on Mac OS X and Linux. On Windows depending on the bit depth we can link to libusb-1.0-32.dll.a or libusb-1.0-64.dll.a. Remember that .a-file can be renamed, but the application will still depend on libusb-1.0.dll. We take parameters for libusb through the system utility pkgconfig in Linux. We include all necessary system libraries and icons in addition to libusb.
It is convenient to distribute the resulting files for different operating systems by directories. You can do it like this:
macx {
DESTDIR = mac
OBJECTS_DIR = mac
MOC_DIR = mac
UI_DIR = mac
RCC_DIR = mac
}
unix: !macx {
DESTDIR = linux
OBJECTS_DIR = linux
MOC_DIR = linux
UI_DIR = linux
RCC_DIR = linux
}
win32 {
DESTDIR = windows/release
OBJECTS_DIR = windows
MOC_DIR = windows
UI_DIR = windows
RCC_DIR = windows
}
win64-x-g++ {
DESTDIR = win64/release
OBJECTS_DIR = win64
MOC_DIR = win64
UI_DIR = win64
RCC_DIR = win64
}
The win64-x-g++ target is for win32. But it is the last one in the project file, so it overwrites the settings.
It is enough to choose the type of assembly (as shown in the very first screenshot) and click “Build project” to compile the application for this or that operating system.
ARTICLES
articles linux windows mac os x qt c++
Leave a comment