自学内容网 自学内容网

Ubuntu20.04 交叉编译Qt5.15.15 for rk3588

    rk3588编译Qt搞了我大半年了,一直困惑特别鸣谢:qq1033878279的网友远程帮我编译演示了一遍。

一、vmware 安装基础工具

sudo apt install  -y build-essential net-tools openssh-server vim openssl libssl-dev

二、vmware 下载 cmake和Qt源码

下载cmake :

wget https://cmake.org/files/v3.31/cmake-3.31.3.tar.gz

 下载Qt5.15.15源码:

wget https://download.qt.io/official_releases/qt/5.15/5.15.15/single/qt-everywhere-opensource-src-5.15.15.tar.xz

下载交叉编译器:

git clone https://github.com/LubanCat/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu.git

三、 vmware 安装 cmake

 ./configure --prefix=/opt/cmake
make
make install

 四、查看 rk3588 arm架构及系统版本

root@ztl:~# uname -a
Linux ztl 5.10.198 #209 SMP Wed Nov 27 09:28:31 CST 2024 aarch64 aarch64 aarch64 GNU/Linux

 查看aarch64,64位的。查看系统:

root@ztl:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

得知rk3588的板子是ubuntu20.04,故vmware虚拟机也得安装ubuntu20.04

五、查看 rk3588 g++版本

root@ztl:~# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/9/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.4.0-1ubuntu1~20.04.2' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2)

查看版本为:

Target: aarch64-linux-gnu

六、 vmware 查看交叉编译器g++

查看 aarch64-none-linux-gnu-g++,得知target为aarch64-none-linux-gnu-

七、修改qmake.conf

根据路径 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)

修改为:

#
# 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-none-linux-gnu-gcc
QMAKE_CXX               = aarch64-none-linux-gnu-g++
QMAKE_LINK              = aarch64-none-linux-gnu-g++
QMAKE_LINK_SHLIB        = aarch64-none-linux-gnu-g++

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

 九、configure

在qt-everywhere-src-5.15.15根目录下打开终端,执行:

export ARCH=aarch64
export CROSS_COMPILE=aarch64-none-linux-gnu-
export PATH=$PATH:/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin

以上PATH为交叉编译器路径。然后继续执行:

./configure \
-xplatform linux-aarch64-gnu-g++ \
-prefix /opt/Qt5.15.15 \
-release \
-opensource \
-skip qtwayland \
-skip qtlocation \
-skip qtscript \
-make libs \
-optimized-qmake \
-no-opengl \
-no-sse2 \
-no-openssl \
-no-cups \
-no-glib \
-no-pkg-config \
-no-separate-debug-info \
-pch \
-shared \
-qt-libjpeg \
-qt-zlib \
-qt-libpng

其中 -xplatform linux-aarch64-gnu-g++ 这里需要注意。

 

 输入 y 回车后继续编译 。

十、执行编译

make
make install

最好不要编译make -j16,否则可能编译失败。

十一、编译Qt 界面程序

在windows创建一个简单的界面程序,不做任何修改,直接拷贝到vmware虚拟机中,执行:

/opt/Qt5.15.15/bin/qmake untitled.pro

然后

make

 拷贝到rk3588的板子上,执行

chmod 777 ./untitled
./untitled

 如图:

如果遇到如下:

zr@ubuntu:/opt/untitled$ /opt/Qt5.15.15/bin/qmake ./untitled.pro
Project ERROR: Cannot run target compiler 'aarch64-none-linux-gnu-g++'. Output:
===================
===================
Maybe you forgot to setup the environment?

 再执行下第九节的:

export ARCH=aarch64
export CROSS_COMPILE=aarch64-none-linux-gnu-
export PATH=$PATH:/opt/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin


 


原文地址:https://blog.csdn.net/sz76211822/article/details/144717107

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!