raspberry-qt Compile and hello world

https://gitorious.org/raspberry-qt/raspberry-qt/source/3c2ed05270137644300cde3b22829380698ff9a9:README.txt#L1
 
 
=== BUILDING CROSS-COMPILED QT 5 FOR RASPBERRY PI ===
Based on http://qt-project.org/wiki/RaspberryPi_Beginners_guide
2/26/2013

1) Create a directory
$ mkdir ~/opt
$ cd ~/opt

2) Download the latest version of Raspbian (http://www.raspberrypi.org/downloads):
$ wget http://files.velocix.com/c1410/images/raspbian/2013-02-09-wheezy-raspbian/2013-02-09-wheezy-raspbian.zip

3) Unzip the image and mount the root filesystem:
$ unzip 2013-02-09-wheezy-raspbian.img
$ sudo mkdir /mnt/rasp-pi-rootfs
$ sudo mount -o loop,offset=62914560 2013-02-09-wheezy-raspbian.img /mnt/rasp-pi-rootfs

4) Download and extract Donald's toolchain:
$ wget http://swap.tsmt.eu/gcc-4.7-linaro-rpi-gnueabihf.tbz
$ tar -xf gcc-4.7-linaro-rpi-gnueabihf.tbz

5) Clone the cross-compile tools
$ git clone git://gitorious.org/raspberry-qt/raspberry-qt.git

6) Fix absolute paths in the Raspberry Pi image
$ sudo ~/opt/raspberry-qt/fixQualifiedLibraryPaths /mnt/rasp-pi-rootfs/ ~/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gcc

7) Install ia32-libs, if on 64-bit machine
$ sudo apt-get install ia32-libs

8) Clone Qt5 and init the repository
$ git clone git://gitorious.org/qt/qt5.git
$ cd qt5
$ ./init-repository

9) If behind firewall and init-repository fails, try:
$ sed -i 's/git:\/\//https:\/\/git./' .gitmodules
./init-repository -f

10) Configure, make, and install Qt 5 base
$ cd qtbase
$ ./configure -opengl es2 -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=~/opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf- -sysroot /mnt/rasp-pi-rootfs -opensource -confirm-license -optimized-qmake -reduce-relocations -reduce-exports -release -make libs -no-pch -prefix /usr/local/qt5pi
$ make -j 4
$ sudo make install

11) If you run into an additional error like http://www.raspberrypi.org/phpBB3/viewtopic.php?t=34103 :
$ sed '33s/#include "vchost_config\.h"/#include "interface\/vmcs_host\/linux\/vchost_config\.h"/' -i /mnt/rasp-pi-rootfs/opt/vc/include/interface/vmcs_host/vcgencmd.h

12) Then build the modules:
for module in qtimageformats qtsvg qtjsbackend qtscript qtxmlpatterns qtdeclarative qtsensors qt3d qtgraphicaleffects; do cd ../$module && /usr/local/qt5pi/bin/qmake . && make -j4 && sudo make install; done

13) Copy the wheezy image to the SD card (WARNING!!! Make sure you know where your sd card is mounted. Use `sudo fdisk -l` if you are uncertain.)
$ cd ~/opt
$ sync && sudo umount /mnt/rasp-pi-rootfs
$ sudo dd bs=1M if=2013-02-09-wheezy-raspbian.img of=/dev/sdc && sync

13) (For OS X)
$ cd ~/opt
$ sudo diskutil umountDisk /dev/disk3
$ sudo dd bs=1M if=2013-02-09-wheezy-raspbian.img of=/dev/rdisk3; sync

=== CONFIGURING RASPBERRY PI ===
1) Select "update" (if you're on a network)
2) Select "expand_rootfs" and let it do its thing
3) Select "configure_keyboard"
---- Select "other"
---- Select "English (US)"
---- Select "The default for the keyboard layout"
---- Select "No compose key"
4) Select "change_locale"
---- Deselect "en_GB.UTF8"
---- Select "en_US.UTF8"
---- Default to "en_US.UTF-8"
5) Select "Finish"
6) Reboot the computer
$ sudo reboot
7) Log in with username "pi", password "raspberry"
8) Get the IP address by looking at "inet addr" under "eth0" after running:
$ ifconfig

=== BUILDING QT 5 ON UBUNTU ===
Based on http://qt-project.org/wiki/Building_Qt_5_from_Git

1) Install dependencies for Qt Webkit, Qt Multimedia, and Libxcb
$ sudo apt-get install "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev build-essential perl python git flex bison gperf libicu-dev libxslt-dev ruby libgstreamer0.10-dev libasound2-dev libatspi2.0-dev libdbus-1-dev git

2) Make directory for this
$ mkdir ~/opt-qt5-local
$ cd ~/opt-qt5-local

3) Clone and init the Qt 5 repository
$ git clone https://git.gitorious.org/qt/qt5.git qt5
$ cd qt5
$ ./init-repository

4) Build Qt
$ ./configure -release -opensource -nomake examples -nomake tests -no-gtkstyle
$ make -j 4
$ sudo make install

=== CONFIGURING QT CREATOR ===
1) Go to the "Build & Run" options
---- Go to Tools -> Options
---- Click "Build & Run"
2) Add the Raspberry Pi cross-compiler
---- Select the "Compilers" tab and click "Add" -> "GCC"
---- Set "Compiler path" to "/home//opt/gcc-4.7-linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-g++"
---- Set "Name" to "GCC RPI"
3) Add the Raspberry Pi Qt version
---- Select "Qt Versions"
---- Click "Add..." and select "/usr/local/qt5pi/bin/qmake"
4) Go to the "Devices" options
---- Click "Devices"
5) Add the Raspberry Pi
---- Click "Add..."
---- Select "Generic Linux Device" and click "Start Wizard"
---- Enter a name for the device
---- Enter the IP address for the device
---- Enter "pi" for the username
---- Enter "raspberry" for the password
6) Go back to "Build & Run"
---- Click "Build & Run"
7) Add the Raspberry Pi kit
---- Click "Add" button
---- Enter "Raspberry Pi" for name
---- Select "Generic Linux Device for device
---- Enter "/mnt/rasp-pi-rootfs" for sysroot
---- Select "GCC RPI" for compiler
---- Browse to ~/opt/gcc-4.7/linaro-rpi-gnueabihf/bin/arm-linux-gnueabihf-gdb for debugger
---- Select qt5pi for Qt Version
8) Click OK

=== BUILDING AN EXAMPLE PROJECT ===
1) Create a new project
---- Select "File" -> "New File or Project"
---- Select "Qt Console Application" and click "Choose..."
---- Call your project "pip" and place it in "~/opt", then click "Next"
---- Ensure "Raspberry Pi" is checked and uncheck any other kits, then click "Next"
---- Click "Finish"
2) Add a new resource file called "main.qrc" in the main directory of the project
3) Add a new QML file called "main.qml" in the main directory of the project
4) Add the QML file to main.qrc
---- Double-click main.qrc
---- Click "Add"->"Add Prefix"
---- Change the prefix to "/"
---- Click "Add"->"Add files" and select "main.qml"
5) Modify main.cpp to show the QML
---- Double-click main.cpp
---- Change the contents to the following:
#include 
#include 
#include 

int main(int argc, char *argv[])
{
 QGuiApplication a(argc, argv);

 QQuickView v;
 v.setResizeMode(QQuickView::SizeRootObjectToView);
 v.setSource(QUrl("qrc:///main.qml"));
 v.showFullScreen();

 return a.exec();
}
5) Modify main.qml to make it more interesting
---- Double-click "main.qml"
---- Change the contents to the following:
import QtQuick 2.0

Rectangle
{
    color: "green"
}
6) Modify pip.pro to deploy all files to the Pi's home directory correctly:
---- Double-click "pip.pro"
---- Change the contents to the following:
QT       += core gui qml quick

TARGET = pip
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app

target.path = /home/pi
INSTALLS += target

SOURCES += main.cpp
RESOURCES += main.qrc
OTHER_FILES += main.qml
7) Deploy the project to the Pi
---- Press F5
---- The Pi's screen should turn green
---- Press the red "STOP" button
---- The Pi's screen should return to normal
---- Press Ctrl-2 to return to Edit mode
8) Congratulations!

=== UPDATING QT5 Repository ===
$ git pull
$ git submodule sync
$ git submodule update --recursive

=== USEFUL NOTES ===
- To clean _everything_ in your qt directory:
$ cd ~/opt/qt5
$ git submodule foreach --recursive git clean -dfx

- Official Raspberry Pi cross-compiler is at https://github.com/raspberrypi/tools

评论

此博客中的热门博文

qtCreator + Eclipse