QT Cross Compile How To
QT Cross Compile How To
https://github.com/EliArad/MyDocuments
Pre-Requisites:
a. you need a raspberry pi board ( I used pi 3)
I used raspbian OS and not the outcome from buildroot , even though I used buildroot.
( next steps will be to use the buildroot image and replace raspbian OS)
b. Download and extract buildroot from https://buildroot.uclibc.org/
c. download the open source QT from https://info.qt.io/download-qt-for-application-development
quick notes on buildroot ( I will create a different tutorial on what I know about buildroot)
I tried make those steps in Qt creator , but I did not succuess yes, because it did not found the
makefile.
So this tutorial ( which take me some time to understand all) will build the gui in QT Creator 5.8
but I will compile and copy the app to raspberry pi 3 using the command line.
I am using xconfig (the qt version gui) but sometimes uses the ncurses menuconfig
(dependencies will come up if they are missing, so just install them)
You should wait for two hours and then see that you have the images ready.
The idea is that we will use buildroot output and creation to cross compile QT.
if you go to output/host/usr where your top level build root is located you will be a directory called
mkspecs
each file define where the compile will be taken from and which compiler for any of the necessary
tools.
Gcc , g++, ar, and so on,
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = arm-linux-gnueabi-gcc
QMAKE_CXX = arm-linux-gnueabi-g++
QMAKE_LINK = arm-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-linux-gnueabi-g++
# modifications to linux.conf
QMAKE_AR = arm-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-linux-gnueabi-objcopy
QMAKE_NM = arm-linux-gnueabi-nm -P
QMAKE_STRIP = arm-linux-gnueabi-strip
load(qt_config)
cp -r linux-arm-gnueabi-g++/ linux-arm-gnueabihf-g++/
now we need to edit the file and add the hf ( the hardware floating point compiler)
#
# qmake configuration for building with arm-linux-gnueabi-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = arm-linux-gnueabihf-gcc
QMAKE_CXX = arm-linux-gnueabihf-g++
QMAKE_LINK = arm-linux-gnueabihf-g++
QMAKE_LINK_SHLIB = arm-linux-gnueabihf-g++
# modifications to linux.conf
QMAKE_AR = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY = arm-linux-gnueabihf-objcopy
QMAKE_NM = arm-linux-gnueabihf-nm -P
QMAKE_STRIP = arm-linux-gnueabihf-strip
load(qt_config)
so I change every place where I have arm-linux-gnueabi-gcc to arm-linux-gnueabihf-gcc
Qt Creator
I did all the steps of creating device , declaring the compile and kit but it did not work
So for now , which is also good step is to document and show how to build the gui in QT and
compile in the command line.
Steps:
1. Download QT Creator 5.X ( I am using 5.8)
2. create a GUI
go to tools→options
Add new..
Again , in this tutorial I choose to document my actions although I cannot compile directly from QT
open the edit mode and select the .ui file or just open the design mode
add some components.
open a terminal and move to the place where QT Creator creates your project
QtTest/HelloPi3Gui
I like to create a source script: name ACTIVATE.sh
1. add to the PATH the location of the build external toolchain,
incase you did not change the settings in buildroot, it will be located at output/host/usr/bin
export PATH=$PATH:/home/elia/Downloads/buildroot_for_raspi3/output/host/usr/bin
Create a compile script ( the killer line) or just run from the command line prompt:
lets explain:
After we run our compile script , we can see that we have Makefile
./../Downloads/buildroot_for_raspi3/output/host/usr/arm-buildroot-linux-
gnueabihf/sysroot/usr/include/qt5/QtCore/qbasicatomic.h:61:4: error: #error "Qt requires C++11
support" # error "Qt requires C++11 support"
here I did the following:
for CXXFLAGS
I want to use GUI and not console because I tried the similar steps with console app and QT4 ( the
default of buildroot)
there I were able to compile from the QT Creator and deploy to the target.
But when I tried to build a widget gui it failed to start.
I read some where the QT4 does not work so I moved to QT5 and it does run.
More notes:
Update:
1. we can create in the linux-arm-gnueabihf-g++/qmake.conf file
a flag for the compiler:
QMAKE_CXXFLAGS = -std=c++11
qmake will not create the Makefile with the C++11 compiler flag so we dont need to
edit the makefile
Upcoming documents:
* Top level of understanding build root , create img deploy and test
* Try fix the above issue and use QT Creator project full to compile and deploy to targeted
* do the same for beaglebone black
* Do the same for Yocto project.