Ubuntu环境下为arm64架构树莓派4交叉编译Qt5的技术问询
环境信息
主机环境
系统版本:Ubuntu 20.04 x64
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 43 bits physical, 48 bits virtual CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 2 Core(s) per socket: 2 Socket(s): 1 NUMA node(s): 1 Vendor ID: AuthenticAMD CPU family: 23 Model: 32 Model name: AMD Athlon Silver 3050e with Radeon Graphics Stepping: 1 Frequency boost: enabled CPU MHz: 946.324 CPU max MHz: 1400,0000 CPU min MHz: 1000,0000 BogoMIPS: 2794.78 Virtualization: AMD-V L1d cache: 64 KiB L1i cache: 128 KiB L2 cache: 1 MiB L3 cache: 4 MiB NUMA node0 CPU(s): 0-3 Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl and seccomp Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Retpolines, IBPB conditional, STIBP always-on, RSB filling Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb hw_pstate sme ssbd sev ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt sha_ni xsaveopt xsavec xgetbv1 xsaves clzero irperf xsaveerptr arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif overflow_recov succor smca
目标设备
设备配置:搭载Ubuntu 22.04 aarch64系统的树莓派4
Architecture: aarch64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Vendor ID: ARM Model name: Cortex-A72 Model: 3 Thread(s) per core: 1 Core(s) per cluster: 4 Socket(s): - Cluster(s): 1 Stepping: r0p3 CPU max MHz: 1800,0000 CPU min MHz: 600,0000 BogoMIPS: 108.00 Flags: fp asimd evtstrm crc32 cpuid Caches (sum of all): L1d: 128 KiB (4 instances) L1i: 192 KiB (4 instances) L2: 1 MiB (1 instance) Vulnerabilities: Itlb multihit: Not affected L1tf: Not affected Mds: Not affected Meltdown: Not affected Spec store bypass: Vulnerable Spectre v1: Mitigation; __user pointer sanitization Spectre v2: Vulnerable Srbds: Not affected Tsx async abort: Not affected
核心问题解答
- 交叉编译器选择:选用Linaro 7分支的
x86_64_aarch64-linux-gnu稳定版(具体版本为gcc-linaro-7.5.0-2019.12)即可,该版本对Cortex-A72架构优化完善,和Ubuntu 22.04自带的glibc 2.35版本兼容性最好,不会出现编译后程序无法在目标机运行的ABI不匹配问题。 - rsync同步目录:双端均为Ubuntu系统时,不需要同步Raspbian场景下的专用固件目录,仅需同步目标机以下目录到主机的交叉编译sysroot路径即可,同步时必须加
-a参数保留软链接,避免链接断裂导致编译报错:/lib:系统基础运行库/usr/lib:用户态安装的所有依赖库/usr/include:系统及第三方依赖的头文件- 若目标机
/opt路径下安装了自定义依赖(如GPU驱动、专用SDK),也需要一并同步
- Qt5 ./configure 适配参数:配置时需要传入的核心参数如下,注意将占位路径替换为本地实际路径:
其中-opensource -confirm-license -release \ -device linux-rasp-pi3-aarch64-gnu++ \ -device-option CROSS_COMPILE=<交叉编译器bin目录下的aarch64-linux-gnu-前缀路径> \ -sysroot <本地rsync同步的目标系统根目录路径> \ -prefix /usr/local/qt5 \ -extprefix <主机端存放编译后可部署到目标机的Qt文件路径> \ -hostprefix <主机端存放Qt宿主工具(qmake、moc、rcc等)的路径> \ -no-use-gold-linker -opengl es2 -eglfs -kms \ -no-pch -qpa eglfs-opengl es2 -kms -eglfs参数是为了适配树莓派4的VC4 GPU硬件加速,避免编译后Qt程序无法调用图形硬件。 - mkspec设备配置选择:选择
linux-rasp-pi3-aarch64-gnu++配置作为基础适配即可。该配置原本针对64位树莓派3的Cortex-A53架构编写,树莓派4所用的Cortex-A72是ARMv8-A架构的向前兼容超集,仅需要将配置文件中的-mtune=cortex-a53修改为-mtune=cortex-a72即可,其余编译选项、EGL/GLES库路径配置和Ubuntu 22.04 aarch64 for 树莓派4的环境完全匹配,无需大规模修改。
内容的提问来源于stack exchange,提问作者ZeusBios
相关产品推荐
相关产品推荐

