qt交叉编译
创建mkspecs文件
参考QT已有mkspecs文件创建自己平台的配置文件,主要用来配置交叉编译的工具链和c库。我们只是孤立的编译QT,没有配置sysroot路径,使用了工具链提供的c库。
# # 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-xilinx-linux-gnueabi-gcc QMAKE_CXX = arm-xilinx-linux-gnueabi-g++ QMAKE_LINK = arm-xilinx-linux-gnueabi-g++ QMAKE_LINK_SHLIB = arm-xilinx-linux-gnueabi-g++ # modifications to linux.conf QMAKE_AR = arm-xilinx-linux-gnueabi-ar cqs QMAKE_OBJCOPY = arm-xilinx-linux-gnueabi-objcopy QMAKE_NM = arm-xilinx-linux-gnueabi-nm -P QMAKE_STRIP = arm-xilinx-linux-gnueabi-strip load(qt_config) QMAKE_LFLAGS += -L/opt/xilinx-arm-toolchain/arm-xilinx-linux-gnueabi/libc/usr/lib
配置QT编译选项,裁剪QT规模
使用了一个脚本来控制编译过程。
#!/bin/bash export PATH=$PATH:/opt/xilinx-arm-toolchain/bin echo $PATH rm -rf qt-everywhere-opensource-src-5.8.0 tar -xvf qt-everywhere-opensource-src-5.8.0.tar.gz cp -R arm-xilinx-linux-gnueabi-g++ qt-everywhere-opensource-src-5.8.0/qtbase/mkspecs/ cd qt-everywhere-opensource-src-5.8.0 ./configure \ -prefix /opt/arm-qt5.8.0 \ -xplatform arm-xilinx-linux-gnueabi-g++ \ -qt-libpng \ -qt-libjpeg \ -no-opengl \ -nomake examples \ -no-qml-debug \ -nomake tests \ -opensource \ -confirm-license \ -skip qt3d \ -skip qtactiveqt \ -skip qtandroidextras \ -skip qtcanvas3d \ -skip qtcharts \ -skip qtconnectivity \ -skip qtdatavis3d \ -skip qtdeclarative \ -skip qtdoc \ -skip qtgamepad \ -skip qtgraphicaleffects \ -skip qtlocation \ -skip qtmacextras \ -skip qtnetworkauth \ -skip qtpurchasing \ -skip qtquickcontrols \ -skip qtquickcontrols2 \ -skip qtscript \ -skip qtscxml \ -skip qtsensors \ -skip qtspeech \ -skip qtsvg \ -skip qttools \ -skip qttranslations \ -skip qtvirtualkeyboard \ -skip qtwayland \ -skip qtwebchannel \ -skip qtwebengine \ -skip qtwebsockets \ -skip qtwebview \ -skip qtwinextras \ -skip qtx11extras \ -skip qtxmlpatterns \ -no-feature-widgets \ -no-feature-dbus \ -no-feature-accessibility \ -no-harfbuzz \ -no-evdev \ -I /home/jeff/code/arm-alsa/include \ -L /home/jeff/code/arm-alsa/lib make -j4 make install
裁剪QT时用到了-skip 和 -no-feature两种配置方式,-skip用于去除整个模块,也就是QT目录下的一级目录;-no-feature用于去除qtcore中的某项功能,具体参考qtbase/src/corelib/global/qfeatures.txt文件。
-prefix用于指定QT的安装路径,此路径会配置在生成的qmake中。
-xplatform用于指定交叉编译时使用的平台,选择之前我们生成的mkspecs文件。
配置QT库工作路径
生成的QT库文件由于qmake中banding了-prefix指定的路径,可以使用qmake -query来查看这些变量,默认情况下我们只能把QT库放置在该路径下才能使用。QT还可以使用qt.conf文件来配置这些变量,我写了如下脚本来配置qt.conf文件,这样我们就可以把QT库放置在任何位置,方便代码管理。
#!/bin/bash Prefix=$(cd "$(dirname "$0")";pwd) Translations=translations Plugins=plugins Imports=imports Examples=examples Demos=demos cat << EOF > $Prefix/bin/qt.conf [Paths] Prefix = $Prefix Translations = $Translations Plugins = $Plugins Imports = $Imports EOF
浙公网安备 33010602011771号