Qt4.8移植到Raspberry主要分为两大步:
1.cross-compiler的建立
2.Qt4.8的交叉编译
具体移植步骤如下:
一、cross-compiler的建立
1.首先准备好PC机,本文用的是Ubuntu 12.04 LTS(装在虚拟机上)
2.Download crosstool-ng from the project web site. I’ve used version 1.15.2 as that was the latest when I wrote this.
3.Unpack the tarball and cd
into the unpacked directory, then run ./configure --prefix=/opt/cross
. You can pick somewhere else instead of /opt/cross
but that’s where I like to keep it.
4.Run make
and sudo make install
.
5.Make sure /opt/cross/bin
is in your $PATH
.
上面都是建立编译环境,然后是对ng工具进行配置,步骤如下:
- Create a directory somewhere in your home directory that crosstool-ng will use as a staging ground. This will contain your toolchain configuration, downloaded files, and intermediary build results. This is not where your final toolchain will end up, and does take up quite a lot of space (3.5GB and up for me).
cd
into your chosen directory. - Run
ct-ng menuconfig
. You should see the ct-ng configuration menu. - Go into Paths and misc options. Enable Try features marked as EXPERIMENTAL.This is important.
- While you’re there you may want to change your Prefix directory. I like to put all my toolchains in
/opt/cross/x-tools/${CT_TARGET}
instead of${HOME}/x-tools/${CT_TARGET}
. - Go back to the main menu and select Target options.
- Change the Target architecture to arm. Leave Endianness set to Little endian andBitness set to 32-bit.
- Go back to the main menu and select Operating system (skip Toolchain options, the defaults are fine).
- Change Target OS to linux.
- Go back to the main menu and select Binary utilities.
- Change binutils version to 2.21.1a or whichever is the latest that isn’t marked as experimental. Probably unnecessary but I prefer this.
- Go back to the main menu and select C compiler.(这一步一定要同时勾选C++编译器,因为后面编译qt会用到)
- Enable the Show Linaro versions (EXPERIMENTAL) option.
- In the gcc version field, choose the linaro-4.6-2012.04 (EXPERIMENTAL) compiler. You’re free to choose a different one but I know this one works well. I do recommend the Linaro versions over the vanilla ones for the RPi.
- All the other settings are fine left at their default values. Exit the configuration tool and save your changes.
- Run
ct-ng build
. - Go away and make a coffee, etc… This bit will take some time.
- You should end up with a freshly baked arm compiler ready for building kernels (and other things) for your Raspberry Pi in your Prefix directory you chose above.
- Just add your compiler directory to your
$PATH
and start compiling. If you used my preferred prefix directory, you would want to add/opt/cross/x-tools/arm-unknown-linux-gnueabi/bin
.
(原文请参考链接http://www.bootc.net/archives/2012/05/26/how-to-build-a-cross-compiler-for-your-raspberry-pi/)
二、Qt4.8的移植
步骤如下:
Building Qt 4.8 Embedded for the Raspberry Pi
Build a cross compiler
Once you have built a cross compiler, I strongly recommend testing it by compiling a test program such as:
#include <iostream> int main(int, char**) { float a = 2.0f * 2.0f; std::cout << "Test " << a << std::endl; return 0; }
Build zLib and OpenSSL
- Download zLib and OpenSSL source packages and extract them.
- Set the following environment variables:
export CC=`/bin/which arm-unknown-linux-gnueabi-gcc` export AR=`/bin/which arm-unknown-linux-gnueabi-ar` export RANLIB=`/bin/which arm-unknown-linux-gnueabi-ranlib`
- Build zLib
cd zlib-1.2.7 ./configure --prefix=/opt/raspi make sudo make install
- Build OpenSSL
cd openssl-1.0.1e ./Configure linux-elf zlib -L/opt/raspi/lib -I/opt/raspi/include --prefix=/opt/raspi no-asm make sudo make install
Build Qt
Download and extract Qt for Embedded Linux.Edit the file in mkspecs/qws/linux-arm-gnueabi-g++/qmake.conf and change the names of the tools to match (mine had built with 'unknown' and not 'none' in the name).
Run the following to build it:
./configure -embedded arm -qt-freetype -prefix /opt/raspi -xplatform qws/linux-arm-gnueabi-g++ -I/opt/raspi/include -L/opt/raspi/lib -no-cups -qt-zlib -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -no-javascript-jit -no-qt3support -qt-gfx-linuxfb -qt-gfx-transformed -plugin-gfx-vnc -qt-kbd-tty -qt-kbd-linuxinput -qt-mouse-pc -qt-mouse-linuxinput -openssl make -j 8 sudo make install
Whilst building I encountered the following problems:
- Error message:
fatal error: .pch/release-shared-emb-arm/QtGui: No such file or directory
This can be fixed by running:
touch src/gui/.pch/release-shared-emb-arm/QtGui
- Error message whilst compiling SerializedScriptValue.o This can be fixed by going in to the directory where it is building (src/3rdparty/webkit/Source/WebCore) and re-running the failed call to g++ but with the -O2 flag changed to -O1
Testing
On the RasPi, before running the demo programs, you need to set the keyboard driver to use with:export QWS_KEYBOARD=linuxinput
You can then run the demo browser with:
/opt/raspi/demos/browser/browser -qws
原文(http://skyhisi.blogspot.com/2013/03/building-qt-48-embedded-for-raspberry-pi.html)