【米尔 NXP i.MX93 开发板评测】搭建QT交叉编译环境
本帖最后由 小麦克 于 2024-8-27 10:14 编辑## QT交叉编译环境
需要提前安装好cmake和ninja
```bash
sudo apt install cmake
sudo apt install ninja-build
```
## 基于Yocto编译环境
关于Yocto环境,米尔专门提供了一篇教程《MYD-LMX9X+QT开发指南.pdf》,里面写的很详细了,我这里就不重复了,有两个地方需要注意一下。
### Sysroot配置问题
教程中的`Sysroot`有点问题,应该为 `/opt/fsl-imx-xwayland/6.1-mickledore/sysroots/armv8a-poky-linux` 而不是 `/opt/fsl-imx-xwayland/6.1-mickledore/sysroots/x86_64-pokysdk-linux`
### CMake构建失败
上面配置都成功了,开始创建QT应用,如果使用`qmake`方式构建应用一切正常。但是如果使用`CMake`方式构建,配置阶段为提示错误:`To use a cross-compiled Qt, please set the QT_HOST_PATH cache variable to the location of your host Qt installation.`
解决方法:需要在`CMakeLists.txt` 中设置 `QT_HOST_PATH`为主机QT的gcc目录,我安装的目录是 `/home/bruce/Qt/6.5.3/gcc_64`
```cmake
set(QT_HOST_PATH /home/bruce/Qt/6.5.3/gcc_64)
```
重新配置后成功了
编译上传测试程序到开发板测试。
## buildroot环境
由于我们之前的根文件系统都是基于`buildroot`,下面来看看怎么在`buildroot`构建的系统上面配置QT的交叉编译环境。
### 构建SDK
确保配置的`buildroot`构建成功,能成功打包成文件系统。下面是我的配置文件(基于当前最新的buildroot仓库-2024-08-27)
```bash
BR2_aarch64=y
BR2_cortex_a55=y
BR2_ARM_FPU_VFPV4D16=y
BR2_KERNEL_HEADERS_6_1=y
BR2_PACKAGE_GLIBC_UTILS=y
BR2_TOOLCHAIN_BUILDROOT_CXX=y
BR2_PACKAGE_HOST_GDB=y
BR2_ENABLE_DEBUG=y
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_MDEV=y
BR2_ROOTFS_MERGED_USR=y
BR2_SYSTEM_DHCP="eth0"
BR2_SYSTEM_DEFAULT_PATH="/bin:/sbin:/usr/bin:/usr/sbin"
BR2_ENABLE_LOCALE_WHITELIST="en_US.UTF-8"
BR2_GENERATE_LOCALE="en_US.UTF-8"
BR2_SYSTEM_ENABLE_NLS=y
BR2_TARGET_TZ_INFO=y
BR2_PACKAGE_ALSA_UTILS=y
BR2_PACKAGE_ALSA_UTILS_ALSACONF=y
BR2_PACKAGE_ALSA_UTILS_ACONNECT=y
BR2_PACKAGE_ALSA_UTILS_ALSALOOP=y
BR2_PACKAGE_ALSA_UTILS_ALSAUCM=y
BR2_PACKAGE_ALSA_UTILS_ALSATPLG=y
BR2_PACKAGE_ALSA_UTILS_AMIDI=y
BR2_PACKAGE_ALSA_UTILS_AMIXER=y
BR2_PACKAGE_ALSA_UTILS_APLAY=y
BR2_PACKAGE_ALSA_UTILS_APLAYMIDI=y
BR2_PACKAGE_ALSA_UTILS_ARECORDMIDI=y
BR2_PACKAGE_ALSA_UTILS_ASEQDUMP=y
BR2_PACKAGE_ALSA_UTILS_ASEQNET=y
BR2_PACKAGE_ALSA_UTILS_BAT=y
BR2_PACKAGE_ALSA_UTILS_IECSET=y
BR2_PACKAGE_ALSA_UTILS_SPEAKER_TEST=y
BR2_PACKAGE_FFMPEG_GPL=y
BR2_PACKAGE_FFMPEG_NONFREE=y
BR2_PACKAGE_FFMPEG_FFPLAY=y
BR2_PACKAGE_FFMPEG_FFPROBE=y
BR2_PACKAGE_FFMPEG_POSTPROC=y
BR2_PACKAGE_FLAC=y
BR2_PACKAGE_GSTREAMER1=y
BR2_PACKAGE_GSTREAMER1_CHECK=y
BR2_PACKAGE_GST1_PLUGINS_BASE_PLUGIN_APP=y
BR2_PACKAGE_GST1_PLUGINS_BAYER2RGB_NEON=y
BR2_PACKAGE_GST1_PLUGINS_GOOD=y
BR2_PACKAGE_GST1_PLUGINS_BAD=y
BR2_PACKAGE_GST1_LIBAV=y
BR2_PACKAGE_GDB=y
BR2_PACKAGE_GDB_SERVER=y
BR2_PACKAGE_GDB_DEBUGGER=y
BR2_PACKAGE_GDB_TUI=y
BR2_PACKAG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PACKAGE_FMT=y
BR2_PACKAGE_PCRE2_32=y
BR2_PACKAGE_DHCPCD=y
BR2_PACKAGE_FREESWITCH=y
BR2_PACKAGE_FREESWITCH_MOD_BCG729=y
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_TCPDUMP=y
BR2_PACKAGE_VSFTPD=y
BR2_PACKAGE_ZSH=y
BR2_PACKAGE_KMOD=y
BR2_PACKAGE_UTIL_LINUX_LIBFDISK=y
BR2_PACKAGE_UTIL_LINUX_AGETTY=y
BR2_PACKAGE_UTIL_LINUX_FSCK=y
BR2_PACKAGE_UTIL_LINUX_HWCLOCK=y
BR2_PACKAGE_UTIL_LINUX_KILL=y
BR2_PACKAGE_UTIL_LINUX_LSFD=y
BR2_PACKAGE_UTIL_LINUX_MORE=y
BR2_PACKAGE_UTIL_LINUX_MOUNT=y
BR2_PACKAGE_UTIL_LINUX_SULOGIN=y
BR2_TARGET_ROOTFS_EXT2=y
BR2_TARGET_ROOTFS_EXT2_SIZE="512M"
BR2_TARGET_ROOTFS_TAR_GZIP=y
BR2_PACKAGE_HOST_ENVIRONMENT_SETUP=y
```
构建SDK,构建成功后,在`output/images`文件夹下会生成 `aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz`SDK,这个SDK可以拷贝到其他电脑或者其他目录,进行应用开发。
```bash
make sdk
```
我这里拷贝到`/home/bruce/Documents`文件夹下,解压,重定位
```bash
# 解压
tar -xf aarch64-buildroot-linux-gnu_sdk-buildroot.tar.gz
# 重定位(只需要执行一次)
cd aarch64-buildroot-linux-gnu_sdk-buildroot/
./relocate-sdk.sh
```
生成新的QT配置,C和C++编译器配置
QT Versions配置,有红色的错误,不用管。
Devices配置
上面都配置好后,最后配置一下Kits,添加一个imx93的配置项。注意`Sysroot`的位置
新建一个CMake QT测试程序,配置为`imx93`,编译,成功!
如果不使用`Qt Creator`,`buildroot`还为我们准备了`environment-setup`脚本,需要交叉编译的时候直接`source`一下,一切就准备就绪了。看下面的示例
```bash
source ~/Documents/aarch64-buildroot-linux-gnu_sdk-buildroot/environment-setup
# 进入qt app目录编译
bruce@ubuntu:~/Documents/qt/qt-apps/test-app/build$ cmake ..
-- The CXX compiler identification is GNU 13.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /home/bruce/Documents/aarch64-buildroot-linux-gnu_sdk-buildroot/bin/aarch64-buildroot-linux-gnu-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Configuring done (1.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/bruce/Documents/qt/qt-apps/test-app/build
bruce@ubuntu:~/Documents/qt/qt-apps/test-app/build$ make
Built target test-app_autogen_timestamp_deps
[ 16%] Automatic MOC and UIC for target test-app
[ 16%] Built target test-app_autogen
[ 33%] Building CXX object CMakeFiles/test-app.dir/test-app_autogen/mocs_compilation.cpp.o
[ 50%] Building CXX object CMakeFiles/test-app.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/test-app.dir/mainwindow.cpp.o
[ 83%] Linking CXX executable test-app
Built target test-app
bruce@ubuntu:~/Documents/qt/qt-apps/test-app/build$ ls
CMakeCache.txtCMakeFilescmake_install.cmakeMakefiletest-apptest-app_autogen
bruce@ubuntu:~/Documents/qt/qt-apps/test-app/build$ file test-app
test-app: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 6.1.0, with debug_info, not stripped
```
可以看到生成的`test-app`就是`ARM aarch64`。
这种方式适合自动化,对项目组提交的代码进行自动编译打包或者测试。
## 树莓派
最近搞了一台8GB的树莓派5,测试下来性能还不错,前提必须上PCI-E固态硬盘,SD卡相对于固态硬盘太慢了。
因为和IMX93使用了同样的`aarch64`架构,接上显示器,用来开发原生QT更简单,不需要配置复杂的交叉编译环境。
我这里通过VNC连接到了树莓派5,安装Qt Creator IDE,编译出的程序可以直接放到开发板运行。需要注意的是i.MX93没有GPU,不支持opengl,因此开发的时候不能调用这些库。否则在开发板加载程序会失败。
## 结论
本篇将QT开发的几种方式都做了测试,欢迎大家指正补充~
<p>i.MX93没有GPU,不支持opengl,开发的时候有点不方便的</p>
Jacktang 发表于 2024-8-28 07:27
i.MX93没有GPU,不支持opengl,开发的时候有点不方便的
<p>和定位有关,工业应用。普通的QT UI应用没问题的,适配了DRM,也能高清显示,最高可达1080p60,一般场景足够了。</p>
页:
[1]