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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM