配置qt的交叉编译工具

配置qt的交叉编译分为以下几步:

  1. 修改qtcreator中的gcc和g++的编译器
  2. 使用新的gcc编译qt源码,得到新的qmake

解压qt源码

tar -xvf qt-everywhere-opensource-src-5.9.9.tar.xz

修改qt配置文件qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf(我选择不修改,仅查看)

$ cat qtbase/mkspecs/linux-aarch64-gnu-g++/qmake.conf 
#
# qmake configuration for building with aarch64-linux-gnu-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                = aarch64-linux-gnu-gcc
QMAKE_CXX               = aarch64-linux-gnu-g++
QMAKE_LINK              = aarch64-linux-gnu-g++
QMAKE_LINK_SHLIB        = aarch64-linux-gnu-g++

# modifications to linux.conf
QMAKE_AR                = aarch64-linux-gnu-ar cqs
QMAKE_OBJCOPY           = aarch64-linux-gnu-objcopy
QMAKE_NM                = aarch64-linux-gnu-nm -P
QMAKE_STRIP             = aarch64-linux-gnu-strip
load(qt_config)

可以看到,交叉编译使用的命令是aarch64-linux-gnu-gcc-ar,而我安装的是aarch64-linux-gnu-gcc-ar-8 ,为了方便,我们选择修改命令名字,不修改qt配置,因为不知道除了这里还有哪里需要一同改动,将所有aarch64-linux-gnu下的带-8的命令做软连接,把-8去掉,

$ sudo ln -s /usr/bin/aarch64-linux-gnu-cpp-8 /usr/bin/aarch64-linux-gnu-cpp
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcc-ranlib-8 /usr/bin/aarch64-linux-gnu-gcc-ranlib
$ sudo ln -s /usr/bin/aarch64-linux-gnu-g++-8 /usr/bin/aarch64-linux-gnu-g++
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcov-8 /usr/bin/aarch64-linux-gnu-gcov
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcov-dump-8 /usr/bin/aarch64-linux-gnu-gcov-dump
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcc-8 /usr/bin/aarch64-linux-gnu-gcc
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcc-ar-8 /usr/bin/aarch64-linux-gnu-gcc-ar
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcov-tool-8 /usr/bin/aarch64-linux-gnu-gcov-tool
$ sudo ln -s /usr/bin/aarch64-linux-gnu-gcc-nm-8 /usr/bin/aarch64-linux-gnu-gcc-nm

修改后结果如下

$ ls -l /usr/bin/aarch64-linux-gnu*
-rwxr-xr-x 1 root root   31768 2月   9 12:37 /usr/bin/aarch64-linux-gnu-addr2line
-rwxr-xr-x 1 root root   64544 2月   9 12:37 /usr/bin/aarch64-linux-gnu-ar
-rwxr-xr-x 1 root root  371528 2月   9 12:37 /usr/bin/aarch64-linux-gnu-as
-rwxr-xr-x 1 root root   31352 2月   9 12:37 /usr/bin/aarch64-linux-gnu-c++filt
lrwxrwxrwx 1 root root      23 5月  11 15:28 /usr/bin/aarch64-linux-gnu-cpp -> aarch64-linux-gnu-cpp-8
-rwxr-xr-x 1 root root 1067960 2月  27  2019 /usr/bin/aarch64-linux-gnu-cpp-8
-rwxr-xr-x 1 root root 3084976 2月   9 12:37 /usr/bin/aarch64-linux-gnu-dwp
-rwxr-xr-x 1 root root   35528 2月   9 12:37 /usr/bin/aarch64-linux-gnu-elfedit
lrwxrwxrwx 1 root root      23 5月  11 15:29 /usr/bin/aarch64-linux-gnu-g++ -> aarch64-linux-gnu-g++-8
-rwxr-xr-x 1 root root 1067960 2月  27  2019 /usr/bin/aarch64-linux-gnu-g++-8
lrwxrwxrwx 1 root root      23 5月  11 15:29 /usr/bin/aarch64-linux-gnu-gcc -> aarch64-linux-gnu-gcc-8
-rwxr-xr-x 1 root root 1067960 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcc-8
lrwxrwxrwx 1 root root      26 5月  11 15:29 /usr/bin/aarch64-linux-gnu-gcc-ar -> aarch64-linux-gnu-gcc-ar-8
-rwxr-xr-x 1 root root   31200 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcc-ar-8
lrwxrwxrwx 1 root root      26 5月  11 15:29 /usr/bin/aarch64-linux-gnu-gcc-nm -> aarch64-linux-gnu-gcc-nm-8
-rwxr-xr-x 1 root root   31200 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcc-nm-8
lrwxrwxrwx 1 root root      30 5月  11 15:30 /usr/bin/aarch64-linux-gnu-gcc-ranlib -> aarch64-linux-gnu-gcc-ranlib-8
-rwxr-xr-x 1 root root   31200 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcc-ranlib-8
lrwxrwxrwx 1 root root      24 5月  11 15:30 /usr/bin/aarch64-linux-gnu-gcov -> aarch64-linux-gnu-gcov-8
-rwxr-xr-x 1 root root  655448 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcov-8
lrwxrwxrwx 1 root root      29 5月  11 15:30 /usr/bin/aarch64-linux-gnu-gcov-dump -> aarch64-linux-gnu-gcov-dump-8
-rwxr-xr-x 1 root root  503760 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcov-dump-8
lrwxrwxrwx 1 root root      29 5月  11 15:30 /usr/bin/aarch64-linux-gnu-gcov-tool -> aarch64-linux-gnu-gcov-tool-8
-rwxr-xr-x 1 root root  528400 2月  27  2019 /usr/bin/aarch64-linux-gnu-gcov-tool-8
-rwxr-xr-x 1 root root   98640 2月   9 12:37 /usr/bin/aarch64-linux-gnu-gprof
lrwxrwxrwx 1 root root      24 2月   9 12:37 /usr/bin/aarch64-linux-gnu-ld -> aarch64-linux-gnu-ld.bfd
-rwxr-xr-x 1 root root 1688200 2月   9 12:37 /usr/bin/aarch64-linux-gnu-ld.bfd
-rwxr-xr-x 1 root root 5314320 2月   9 12:37 /usr/bin/aarch64-linux-gnu-ld.gold
-rwxr-xr-x 1 root root   44784 2月   9 12:37 /usr/bin/aarch64-linux-gnu-nm
-rwxr-xr-x 1 root root  175528 2月   9 12:37 /usr/bin/aarch64-linux-gnu-objcopy
-rwxr-xr-x 1 root root  341496 2月   9 12:37 /usr/bin/aarch64-linux-gnu-objdump
-rwxr-xr-x 1 root root   64544 2月   9 12:37 /usr/bin/aarch64-linux-gnu-ranlib
-rwxr-xr-x 1 root root  568280 2月   9 12:37 /usr/bin/aarch64-linux-gnu-readelf
-rwxr-xr-x 1 root root   31648 2月   9 12:37 /usr/bin/aarch64-linux-gnu-size
-rwxr-xr-x 1 root root   31816 2月   9 12:37 /usr/bin/aarch64-linux-gnu-strings
-rwxr-xr-x 1 root root  175528 2月   9 12:37 /usr/bin/aarch64-linux-gnu-strip

然后执行./configure的命令(这个配置命令需要根据实际情况修改)

./configure  -opensource -confirm-license -extprefix /opt/aarch64-qt -xplatform linux-aarch64-gnu-g++  -no-opengl

配置通过,进行编译

make -j8 
sudo make install
  1. 修改qtcreator中的qt版本(qmake)
  2. 运行代码检查环境