当前位置:   article > 正文

嵌入式linux之QT交叉编译环境搭建(最简单实测通用版)

嵌入式linux之QT交叉编译环境搭建(最简单实测通用版)

这里总结下用于嵌入式linux下的QT交叉编译环境搭建,留作备忘,分享给有需要的小伙伴。不管你的是什么嵌入式linux环境,实测过的通用方法总结。

环境准备

需要准备的环境要求如下:

1.虚拟机(vmvare15.5)

2.ubuntu18.04-x64的linux系统镜像

3.qt安装包(qt-5.12.9)

4.交叉编译工具链(一般厂家会提供)

vmvare15.5下载

VMWare (Virtual Machine ware)是一个虚拟机软件,它可以使你在一台机器上同时运行二个或更多Windows、DOS、LINUX系统。

 下载地址

VMware-workstation-full-15.5.0-14665864.exe_免费高速下载|百度网盘-分享无限制

虚拟机的网络设置

 NAT 连接方式

默认情况下,虚拟机安装完成后网络连接方式如下图所示为 NAT,与宿主机共享一个 IP 地址,我们在进行依赖包的安装,代码的编译等工作时是不需要更改的。
在虚拟机中,VMware 虚拟网卡设置为 NAT 模式时,Ubuntu 环境中网络设置为动态 IP 即可。在这种模式下虚拟 NAT 设备和主机网卡相连通信上网。这种事我们虚拟机上外网最常用的方式。

桥接的连接方式
VMware 虚拟网卡设备为桥接模式时,主机网卡和虚拟机网卡通过虚拟网桥进行通信,需要在 Ubuntu环境中设置网络 IP 与主机在同一个网段,如果需要上外网需要设置 DNS 与主机网卡一致。如果在使用TFTP,SFTP 等服务器时则需要设置虚拟机的网络联系方式为桥接方式。

更新系统镜像源

ubuntu18自带的镜像源下载很慢,替换镜像源的是必要的。免不了要联网下载安装一些东西。

先备份:cp /etc/apt/sources.list   /etc/apt/sources.list.bak
再将以下源文件复制到/etc/apt/sources.list

可以使用Vi或者gedit打开。

阿里镜像源

  1. deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  2. deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
  3. deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  4. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
  5. deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  6. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
  7. deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  8. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
  9. deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
  10. deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

华为镜像源

  1. # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
  2. # newer versions of the distribution.
  3. deb http://repo.huaweicloud.com/ubuntu jammy main restricted
  4. # deb-src http://repo.huaweicloud.com/ubuntu jammy main restricted
  5.  
  6. ## Major bug fix updates produced after the final release of the
  7. ## distribution.
  8. deb http://repo.huaweicloud.com/ubuntu jammy-updates main restricted
  9. # deb-src http://repo.huaweicloud.com/ubuntu jammy-updates main restricted
  10.  
  11. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  12. ## team. Also, please note that software in universe WILL NOT receive any
  13. ## review or updates from the Ubuntu security team.
  14. deb http://repo.huaweicloud.com/ubuntu jammy universe
  15. # deb-src http://repo.huaweicloud.com/ubuntu jammy universe
  16. deb http://repo.huaweicloud.com/ubuntu jammy-updates universe
  17. # deb-src http://repo.huaweicloud.com/ubuntu jammy-updates universe
  18.  
  19. ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
  20. ## team, and may not be under a free licence. Please satisfy yourself as to
  21. ## your rights to use the software. Also, please note that software in
  22. ## multiverse WILL NOT receive any review or updates from the Ubuntu
  23. ## security team.
  24. deb http://repo.huaweicloud.com/ubuntu jammy multiverse
  25. # deb-src http://repo.huaweicloud.com/ubuntu jammy multiverse
  26. deb http://repo.huaweicloud.com/ubuntu jammy-updates multiverse
  27. # deb-src http://repo.huaweicloud.com/ubuntu jammy-updates multiverse
  28.  
  29. ## N.B. software from this repository may not have been tested as
  30. ## extensively as that contained in the main release, although it includes
  31. ## newer versions of some applications which may provide useful features.
  32. ## Also, please note that software in backports WILL NOT receive any review
  33. ## or updates from the Ubuntu security team.
  34. deb http://repo.huaweicloud.com/ubuntu jammy-backports main restricted universe                                                                                                    multiverse
  35. # deb-src http://repo.huaweicloud.com/ubuntu jammy-backports main restricted uni                                                                                                   verse multiverse
  36.  
  37. deb http://repo.huaweicloud.com/ubuntu jammy-security main restricted
  38. # deb-src http://repo.huaweicloud.com/ubuntu jammy-security main restricted
  39. deb http://repo.huaweicloud.com/ubuntu jammy-security universe
  40. # deb-src http://repo.huaweicloud.com/ubuntu jammy-security universe
  41. deb http://repo.huaweicloud.com/ubuntu jammy-security multiverse
  42. # deb-src http://repo.huaweicloud.com/ubuntu jammy-security multiverse

编译环境依赖配置

  1. sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386 libc6:i386
  2. // 32位兼容依赖库
  3. //使用网络配置工具和 menuconfig 时还需要安装以下库:
  4. linx@ubuntu:~$ sudo apt-get update //更新下载源信息
  5. linx@ubuntu:~$ sudo apt-get install net-tools //网络配置工具
  6. sudo apt-get install lzop // 安装 lzop 工具,用于生成压缩或解压镜像
  7. sudo apt-get install libncurses* // 安装 ncurese 相关库,U-boot 或者内核菜单显示时需要
  8. //安装一些三方开源库需要
  9. sudo apt-get install -y autoconf automake libtool
  10. sudo apt-get install autoconf-archive
  11. sudo apt-get install m4
  12. sudo apt install pkg-config

QT下载

https://download.qt.io/archive/qt/

注意事项

QT的安装包可以直接从官网下载linux上的安装包,安装即可。如:https://download.qt.io/archive/qt/5.12/5.12.9/ qt-opensource-linux-x64-5.12.9.run

注意事项,因为最终目的是开发板的嵌入式环境下使用。所以上述只是安装了在linux电脑上的QT环境。最终是需要交叉编译,才可以在嵌入式linux板上运行。需要确定下你的交叉编译工具链是否包含了QT的头文件和库。一般开发板厂家都提供了现成的包含QT的交叉编译工具链,所以不需要从新编译QT的源码。打开Qtcreater,只需配置交叉编译的工具链即可。

有的文章中介绍的很麻烦,比如单独安装qtcreater之类的不需要的。直接下载的qt5.12.9中包含qt的sdk和qtcreater。

安装QT遇到的问题

Qt version is not properly installed,please run make install

1.直接copy别人安装好的QT库,在自己电脑上编译时提示Qt version is not properly installed,please run make install。

2.从网上查找发现原因:原来是qmake.exe是在Qt安装编译时生成的,里面内嵌了Qt相关的一些路径。如果直接copy过来,自己的路径结构与原来不同,则Qt库就不能正常使用。

3.解决方法:在qmake.exe所在目录新建一个文本文件,将下面的内容写入文本文件,并将文件命名为qt.conf即可。
内容修改:

  1. [Paths]
  2. Prefix=/usr
  3. HostPrefix=/home/t507/tmp/OKT507/err_OKT507_buildroot/OKT507-linux-sdk/out/t507/okt507/longan/buildroot/host
  4. Sysroot=/home/t507/tmp/OKT507/err_OKT507_buildroot/OKT507-linux-sdk/out/t507/okt507/longan/buildroot/host/aarch64-buildroot-linux-gnu/sysroot
  5. Headers=/usr/include/qt5
  6. Plugins=/usr/lib/qt/plugins
  7. Examples=/usr/lib/qt/examples

error: Cannot run target compiler '/home/t507/tmp/OKT507/err_OKT507_buildroot/OKT507-linux-sdk/out/t507/okt507/longan/buildroot/host/bin/aarch64-linux-gnu-g++'. Output:

报这个错是因为从别处拷贝的别人的工具链。那么很多软链接应该是找不到的。需要运行以下脚本,删除旧的工具链的软链接,从新建立新的软链接。

changeSdkLocation.sh脚本内容如下:

  1. #!/bin/sh
  2. #
  3. if [ "$#" -ne 0 ]; then
  4. echo "Run this script to relocate the buildroot SDK at that location"
  5. exit 1
  6. fi
  7. LOCFILE="share/buildroot/sdk-location"
  8. FILEPATH="$(readlink -f "$0")"
  9. NEWPATH="$(dirname "${FILEPATH}")"
  10. LICHEE_BR_OUT="/opt/okt507/buildroot"
  11. LICHEE_OUT_DIR="/opt/okt507/buildroot"
  12. cd "${NEWPATH}"
  13. if [ ! -r "${LOCFILE}" ]; then
  14. echo "Previous location of the buildroot SDK not found!"
  15. exit 1
  16. fi
  17. OLDPATH="$(cat "${LOCFILE}")"
  18. #if [ "${NEWPATH}" = "${OLDPATH}" ]; then
  19. # echo "This buildroot SDK has already been relocated!"
  20. # exit 0
  21. #fi
  22. FIX_LIST="
  23. aarch64-linux-gnu-addr2line \
  24. aarch64-linux-gnu-ar \
  25. aarch64-linux-gnu-as \
  26. aarch64-linux-gnu-c++ \
  27. aarch64-linux-gnu-c++filt \
  28. aarch64-linux-gnu-cpp \
  29. aarch64-linux-gnu-dwp \
  30. aarch64-linux-gnu-elfedit \
  31. aarch64-linux-gnu-g++ \
  32. aarch64-linux-gnu-gcc \
  33. aarch64-linux-gnu-gcc-7.4.1 \
  34. aarch64-linux-gnu-gcc-ar \
  35. aarch64-linux-gnu-gcc-nm \
  36. aarch64-linux-gnu-gcc-ranlib \
  37. aarch64-linux-gnu-gcov \
  38. aarch64-linux-gnu-gcov-dump \
  39. aarch64-linux-gnu-gcov-tool \
  40. aarch64-linux-gnu-gdb \
  41. aarch64-linux-gnu-gdb-add-index \
  42. aarch64-linux-gnu-gfortran \
  43. aarch64-linux-gnu-gprof \
  44. aarch64-linux-gnu-ld \
  45. aarch64-linux-gnu-ld.bfd \
  46. aarch64-linux-gnu-ld.gold \
  47. aarch64-linux-gnu-nm \
  48. aarch64-linux-gnu-objcopy \
  49. aarch64-linux-gnu-objdump \
  50. aarch64-linux-gnu-ranlib \
  51. aarch64-linux-gnu-readelf \
  52. aarch64-linux-gnu-size \
  53. aarch64-linux-gnu-strings \
  54. aarch64-linux-gnu-strip
  55. "
  56. for str in $FIX_LIST
  57. do
  58. rm bin/$str
  59. ln -s $LICHEE_OUT_DIR/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/$str $LICHEE_BR_OUT/host/bin/$str
  60. done
  61. [ -L $LICHEE_BR_OUT/staging ] && rm $LICHEE_BR_OUT/staging
  62. ln -s $LICHEE_BR_OUT/host/aarch64-buildroot-linux-gnu/sysroot $LICHEE_BR_OUT/staging
  63. # Check if the path substitution does work properly, e.g. a tree
  64. # "/a/b/c" copied into "/a/b/c/a/b/c/" would not be allowed.
  65. newpath="$(sed -e "s|${OLDPATH}|${NEWPATH}|g" "${LOCFILE}")"
  66. if [ "${NEWPATH}" != "${newpath}" ]; then
  67. echo "Something went wrong with substituting the path!"
  68. echo "Please choose another location for your SDK!"
  69. exit 1
  70. fi
  71. echo "Relocating the buildroot SDK from ${OLDPATH} to ${NEWPATH} ..."
  72. # Make sure file uses the right language
  73. export LC_ALL=C
  74. # Replace the old path with the new one in all text files
  75. grep -lr "${OLDPATH}" . | while read -r FILE ; do
  76. if file -b --mime-type "${FILE}" | grep -q '^text/' && [ "${FILE}" != "${LOCFILE}" ]
  77. then
  78. sed -i "s|${OLDPATH}|${NEWPATH}|g" "${FILE}"
  79. fi
  80. done
  81. # At the very end, we update the location file to not break the
  82. # SDK if this script gets interruted.
  83. sed -i "s|${OLDPATH}|${NEWPATH}|g" ${LOCFILE}

接着又报错: 

原因是,gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu\libexec\gcc\aarch64-linux-gnu\7.4.1\liblto_plugin.so ,该软连接失效了,从新软链接下。

软链接失效的问题, 最可能是从windows下直接拷贝导致的。建议拷贝到虚拟机中,不要直接拷贝文件夹。正确做法应该是解压缩。

其他资源

ubuntu搭建qt的arm交叉编译环境_ubuntu编译qt源码_小爷帅的惊动d的博客-CSDN博客

Ubuntu20.04.1(X86_64)Qt5.14.2配置ARM64交叉编译环境_Kwok HQ的博客-CSDN博客

https://www.cnblogs.com/dancefire/archive/2011/03/09/fix-bad-superblock-in-linux.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/235020
推荐阅读
相关标签
  

闽ICP备14008679号