首先从获得最新版本的Raspbian或5月23日版本(我用于本教程的版本)开始。您至少需要一张16GB的SD卡,因为所需的空间有点超过4GB(8G SD卡可能不够用)。还要确保您使用的是具有512MB RAM的B型或B型。早期的树莓派装有256 MB的RAM,这是不够的,并会导致gcc错误。
打开Raspberry Pi并登录。确保它已正确连接到互联网,并且您的电源至少为1A。你可能也想超频你的Pi。我以900 MHz的频率超频,花了38个小时编译,温度稳定在51 C - 54 C(带外壳,没有散热片,没有风扇)。
安装编译所需的软件包:
sudo apt-get update sudo apt-get upgrade sudo apt-get install libfontconfig1-dev libdbus-1-dev libfreetype6-dev libudev-dev libicu-dev libsqlite3-dev libxslt1-dev libssl-dev libasound2-dev libavcodec-dev libavformat-dev libswscale-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev gstreamer-tools gstreamer0.10-plugins-good gstreamer0.10-plugins-bad libraspberrypi-dev libpulse-dev libx11-dev libglib2.0-dev libcups2-dev freetds-dev libsqlite0-dev libpq-dev libiodbc2-dev libmysqlclient-dev firebird-dev libpng12-dev libjpeg9-dev libgst-dev libxext-dev libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync1 libxcb-sync-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev libxi-dev libdrm-dev libssl-dev libxcb-xinerama0 libxcb-xinerama0-dev
2017年3月23日更新:对于PI3,使用最新版本的Raspbian(4.4.5),汇编需要过夜。
然后让你的构建目录:
mkdir ~/opt
cd ~/opt
从git中检索qt5源代码:
git clone git://code.qt.io/qt/qt5.git
检索其他组件的git源代码
cd qt5
./init-repository
不要应用任何可用的补丁。 最新的Qt5不再需要它们。 git源代码应该在配置参数中使用一些技巧进行编译,而不需要任何补丁。
首先确保你在qt5目录中。
cd ~/opt/qt5
为了使配置脚本正确构建所有的Makefiles,您需要调整〜/opt/qt5/qtbase/configure脚本。使用您最喜欢的文本编辑器(vim,nano,emacs),并在〜/opt/qt5/qtbase/configure脚本(搜索QT_CFLAGS_DBUS)中更改/添加以下代码:
# flags for raspberry pi build # flags for libdbus-1 QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/" QT_LIBS_DBUS=-ldbus-1 # flags for Glib (X11 only) QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/" QT_LIBS_GLIB=-lglib-2.0 QT_CFLAGS_PULSEAUDIO="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/" QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib" # flags for GStreamer (X11 only) QT_CFLAGS_GSTREAMER="-I/usr/include/gstreamer-0.10/ -I/usr/include/glib-2.0/ -I/usr/lib/arm-linux- gnueabihf/glib-2.0/include/ -I/usr/include/libxml2/" QT_LIBS_GSTREAMER=
然后在配置脚本中关闭文件搜索QT_CFLAGS_FONTCONFIG之前。 它应该位于上面的条目下方,您需要将else语句中的条目更改为:
QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/
如果上述更改很难遵循,则可以使用以下修补程序文件:
1030,1031c1030,1031 < QT_CFLAGS_DBUS= < QT_LIBS_DBUS= — > QT_CFLAGS_DBUS="-I/usr/include/dbus-1.0/ -I/usr/lib/arm-linux-gnueabihf/dbus-1.0/include/" > QT_LIBS_DBUS=-ldbus-1 1034,1035c1034,1038 < QT_CFLAGS_GLIB= < QT_LIBS_GLIB= — > QT_CFLAGS_GLIB="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/" > QT_LIBS_GLIB=-lglib-2.0 > > QT_CFLAGS_PULSEAUDIO="-I/usr/include/glib-2.0/ -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include/" > QT_LIBS_PULSEAUDIO="-lpulse -lpulse-mainloop-glib" 1038c1041 < QT_CFLAGS_GSTREAMER= — > QT_CFLAGS_GSTREAMER="-I/usr/include/gstreamer-0.10/ -I/usr/include/glib-2.0/ -I/usr/lib/arm-linux- gnueabihf/glib-2.0/include/ -I/usr/include/libxml2/" 5123c5126 < QT_CFLAGS_FONTCONFIG= — > QT_CFLAGS_FONTCONFIG=-I/usr/include/freetype2/为了在Raspberry Pi上正确运行Qt5的配置,需要将CROSS_COMPILE变量指向位于/usr/bin/g++的本机编译器。 CROSS_COMPILE参数是编译器的路径(不含g)。 如果你不这样做,它会抱怨说它没有被交叉编译。
所有输出存储在称为“输出”的文件中,以防出现问题。 在输出文件的末尾,应该说你可以运行'make',如果不在输出结尾查找错误。
不要担心由于缺少软件包而造成的某些事情不会发生,那些错误将会出现。 如果它没有提到你可以运行make,然后检查最后一个错误,它通常是显示停止。 运行配置:
./configure -v -opengl es2 -device linux-rasp-pi-g''+ -device-option CROSS_COMPILE=/usr/bin/ -opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs -prefix /usr/local/qt5 &> output2017年3月23日更新:对于带有最新版Raspbian(4.4.5)的PI3,在预编译头文件时遇到问题,必须在./configure(在上面的代码中)中使用-no-pch参数。
检查输出文件,看看它是在构建你需要的组件(在输出结束时,它将在将要构建的Qt组件旁边有Yes),并且应该说你现在可以运行'make'。
'输出'文件中的示例:
… Build options: Configuration ………. accessibility accessibility-atspi-bridge alsa audio-backend c+''11 clock-gettime clock-monotonic concurrent cross_compile cups dbus egl eglfs evdev eventfd fontconfig full-config getaddrinfo getifaddrs glib gstreamer iconv icu inotify ipv6ifname large-config largefile libudev linuxfb medium-config minimal-config mremap neon nis no-pkg-config opengl opengles2 openssl pcre png precompile_header pulseaudio qpa qpa reduce_exports reduce_relocations release rpath shared small-config system-freetype system-jpeg system-png system-zlib v8 v8snapshot xcb xcb-glx xcb-render xcb-xlib xinput2 xkbcommon-qt xlib xrender Build parts ………… libs Mode ………………. release Using C''+11 ………… yes Using PCH ………….. yes Target compiler supports: iWMMXt/Neon ………. no/yes Qt modules and options: Qt D-Bus …………… yes (loading dbus-1 at runtime) Qt Concurrent ………. yes Qt GUI …………….. yes Qt Widgets …………. yes JavaScriptCore JIT ….. yes (To be decided by JavaScriptCore) QML debugging ………. yes Use system proxies ….. no Support enabled for: Accessibility ………. yes ALSA ………………. yes CUPS ………………. yes FontConfig …………. yes Iconv ……………… yes ICU ……………….. yes Image formats: GIF ……………… yes (plugin, using system library) JPEG …………….. yes (plugin, using system library) PNG ……………… yes (in QtGui, using system library) Glib ………………. yes GStreamer ………….. yes GTK theme ………….. no Large File …………. yes libudev ……………. yes Networking: getaddrinfo ………. yes getifaddrs ……….. yes IPv6 ifname ………. yes OpenSSL ………….. yes (loading libraries at run-time) NIS ……………….. yes OpenGL …………….. yes (OpenGL ES 2.x) OpenVG …………….. no PCRE ………………. yes (bundled copy) pkg-config …………. no PulseAudio …………. yes QPA backends: DirectFB …………. no EGLFS ……………. yes KMS ……………… no LinuxFB ………….. yes XCB ……………… yes (system library) MIT-SHM ………… yes Xcursor ………… yes (loaded at runtime) Xfixes …………. yes (loaded at runtime) Xi …………….. no Xi2 ……………. yes Xinerama ……….. yes (loaded at runtime) Xrandr …………. yes (loaded at runtime) Xrender ………… yes XKB ……………. no XShape …………. yes XSync ………….. yes XVideo …………. yes Session management ….. yes SQL drivers: DB2 ……………… no InterBase ………… no MySQL ……………. yes (plugin) OCI ……………… no ODBC …………….. yes (plugin) PostgreSQL ……….. yes (plugin) SQLite 2 …………. yes (plugin) SQLite …………… yes (plugin, using bundled copy) TDS ……………… yes (plugin) udev ………………. yes xkbcommon ………….. yes (bundled copy) zlib ………………. yes (system library) NOTE: libxkbcommon 0.2.0 (or higher) not found on the system, will use the bundled version from 3rd party directory. Qt is now configured for building. Just run 'make'. Once everything is built, you must run 'make install'. Qt will be installed into /usr/local/qt5 Prior to reconfiguration, make sure you remove any leftovers from the previous build.
请注意,汇编将花费大约两天的时间来编译900 MHz超频。 如果您远程登录,请考虑使用byobu或屏幕,以便您可以分离会话。
然后,您需要按如下所示运行make(检查output_make文件中的错误):make &> output_make
如果那是好的,那么运行make install(检查output_make_install文件中的错误):
sudo make install &> output_make_install
在此之后,你需要添加一些行到你的.bashrc文件中:
export LD_LIBRARY_PATH=/usr/local/qt5/lib/
export PATH=/usr/local/qt5/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
您需要获取.bashrc文件来设置上述环境变量:
source ~/.bashrc
然后运行它并检查它是否指向/usr/local/qt5/bin/qmake
which qmake
示例输出:
pi@raspberrypi ~/opt/qt5 $ which qmake
/usr/local/qt5/bin/qmake
在此之后,您应该能够编译示例应用程序并运行它们。 试试OpenGL Cube(我没有在X窗口中测试过,只能从控制台中):
cp -r~/opt/qt5/qtbase/examples/opengl/cube ~/
cd~/cube
qmake
make
./cube