Cross Compiling Qt
On of the great aspects of Qt is that it is cross platform. Not only across desktops, but also across devices. The Qt make tool, qmake, can be configured to cross compile for different architectures using different compilers and different settings. How to do all this is reasonably straight forward, but you need to know how to get started.
When you've downloaded and extracted Qt you find yourself facing a configure script with loads of options. Trying to get control of them all can feel overwhelming the first time, so it is good to know what is about to happen.
When you run configure, the build tool, qmake, is built, containing the configuration. This has the implication that you can have multiple qmake binaries for different build targets. QMake is then used to build Qt for the target.
Qt is built from a set of modules, which are separate libraries. This means that you do not have to decide on which modules to use when configuring. Instead, just build everything and make the decision later (using the QT variable in your project file - this is outside the scope of this article). The same applies to plugins (database drivers, image formats, etc).
What is important is if you want to build Qt static or dynamic, if you want to use platform libs for various features (libjpeg, zlib, libpng, etc). Another important, and not so straight forward, configuration option is the compiler to use. This is controlled by what is known as an mkspec - a make specification.
Qt comes with quite a few prepared mkspecs, but it is not uncommon to tweak them a little. They are all kept in the mkspec subdirectory of Qt, with another subdirectory for embedded targets called qws. The spec consists of the files qmake.conf and qplatformdefs.h. The latter is pretty easy to reuse between Linuxes. It defines a number of structures and functions for the underlaying system. The former, qmake.conf, tells qmake how to compile.
Once having found the file, reading it is pretty straight forward. For instance, the QMAKE_CXX variable should list the C++ compiler to use, QMAKE_CXXFLAGS lists the flags to use when invoking the C++ compiler, and so on.
Having all this in place, simply use the -xplatform to specify the spec to use. This argument uses the mkspec directory as base, so to use the $(QTDIR)/mkspec/qws/linux-arm-g++ specify -xplatform qws/linux-arm-g++.
Finally, adding the arguments -nomake demos and -nomake examples can save quite a lot of time.
Johan Thelin is a consultant working with Qt, embedded and free
software. On-line, he is known as e8johan.
|openHAB||Apr 24, 2017|
|Omesh Tickoo and Ravi Iyer's Making Sense of Sensors (Apress)||Apr 21, 2017|
|Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi||Apr 20, 2017|
|CodeLathe's Tonido Personal Cloud||Apr 19, 2017|
|Wrapping Up the Mars Lander||Apr 18, 2017|
|MultiTaction's MT Canvus-Connect||Apr 17, 2017|
- Teradici's Cloud Access Platform: "Plug & Play" Cloud for the Enterprise
- The Weather Outside Is Frightful (Or Is It?)
- Understanding Firewalld in Multi-Zone Configurations
- Simple Server Hardening
- Low Power Wireless: 6LoWPAN, IEEE802.15.4 and the Raspberry Pi
- Non-Linux FOSS: Control Web-Based Music!
- Buddy Platform Limited's Parse on Buddy Service
- Linux Journal February 2017