PDA

View Full Version : Configuring QtCreator (and/or qmake) for Ubuntu->Raspbian cross compile



davethomaspilot
7th December 2014, 15:37
I've been building Qt applications (Qt4.8) natively on raspberry pi (Raspbian) for some time now, with no issues ( The project has grown -- so now it takes a really long time to compile.

I followed a nice tutorial (Hertaville) to set up cross-compilation on Ubuntu 12 for a Raspbian target. It works, and the performance improvement is huge (10 minutes down to about 30 seconds). However, the resulting flow doesn't use QtCreator, which I now really like and don't want to give up.

So, the cross-compile toolchain is setup and working. The target file system is mounted, which I'd think would eliminate the need to rebuild any Qt binaries, but maybe not?

I tried setting up a Qt version and tool chain in Qt Creator on the Ubuntu machine, but so far, without success. I've seen some issues with how toolchains and Qt versions are set up in QtCreator, and I'm beginning to think those might prevent me from doing what I want to do.

Should I be able to do this somehow, maybe with QMAKESPECS or with qmake variables?

Or, is it necessary to build a qmake from source if I want to use QtCreator to cross-compile (and debug) raspian applications from Ubuntu?

davethomaspilot
13th December 2014, 17:08
Answering my own question, but I followed this tutorial to get cross-compilation of qt4 applicatins working outside qtcreator:

hertaville.com/2014/04/12/cross-compiling-qt4-app/

Then, instead of using the Makefile in that tutorial, I copied a mkspecs directory and edited its qmake.conf for the same configuration options:



#
# qmake configuration for linux-arm-g++
#

CROSS_COMPILE = arm-linux-gnueabihf
ROOTFS = /home/davethomaspilot/rpi/mntrpi
MAKEFILE_GENERATOR = UNIX
TARGET_PLATFORM = unix
TEMPLATE = app
CONFIG += qt warn_on release incremental link_prl gdb_dwarf_$
QT += core gui
QMAKE_INCREMENTAL_STYLE = sublib

include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
QMAKE_CXX = $$CROSS_COMPILE-g++
QMAKE_LINK = $$CROSS_COMPILE-g++
QMAKE_LINK_SHLIB = $$CROSS_COMPILE-g++
QMAKE_AR = $$CROSS_COMPILE-ar cr
QMAKE_OBJCOPY = $$CROSS_COMPILE-objcopy
QMAKE_STRIP = $$CROSS_COMPILE-strip
QMAKE_LFLAGS_RELEASE = -Wl,-O1
QMAKE_RPATHDIR += $$ROOTFS/lib/arm-linux-gnueabihf
QMAKE_RPATHDIR += $$ROOTFS/usr/lib/arm-linux-gnueabihf
QMAKE_INCDIR = $$ROOTFS/usr/include
QMAKE_INCDIR_QT = $$ROOTFS/usr/include/qt4
QMAKE_RPATHDIR = $$ROOTFS/lib/arm-linux-gnueabihf
QMAKE_RPATHDIR += $$ROOTFS/usr/lib/arm-linux-gnueabihf
QMAKE_LIBDIR = $$ROOTFS/usr/lib
QMAKE_LIBDIR_QT = $$ROOTFS/usr/lib/arm-linux-gnueabihf
QMAKE_LIBDIR_QT += $$ROOTFS/lib/arm-linux-gnueabihf
QMAKE_INCDIR_X11 = $$ROOTFS/usr/include
QMAKE_LIBDIR_X11 = $$ROOTFS/usr/lib/arm-linux-gnueabihf
QMAKE_LIBDIR_X11 += $$ROOTFS/lib/arm-linux-gnueabihf
QMAKE_INCDIR_OPENGL = $$ROOTFS/usr/include
QMAKE_LIBDIR_OPENGL = $$ROOTFS/usr/lib

load(qt_config)


Then, as Wysota suggested in another thread, I used the -spec qmake option to specify the new "linux-arm-g++" mkspec.

Works great and now I get fast compile times, less than a minute on my W520 laptop versus over 10 minutes using native compile on the rpi.