这里总结下用于嵌入式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打开。
阿里镜像源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
华为镜像源
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://repo.huaweicloud.com/ubuntu jammy main restricted
# deb-src http://repo.huaweicloud.com/ubuntu jammy main restricted## Major bug fix updates produced after the final release of the
## distribution.
deb http://repo.huaweicloud.com/ubuntu jammy-updates main restricted
# deb-src http://repo.huaweicloud.com/ubuntu jammy-updates main restricted## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://repo.huaweicloud.com/ubuntu jammy universe
# deb-src http://repo.huaweicloud.com/ubuntu jammy universe
deb http://repo.huaweicloud.com/ubuntu jammy-updates universe
# deb-src http://repo.huaweicloud.com/ubuntu jammy-updates universe## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://repo.huaweicloud.com/ubuntu jammy multiverse
# deb-src http://repo.huaweicloud.com/ubuntu jammy multiverse
deb http://repo.huaweicloud.com/ubuntu jammy-updates multiverse
# deb-src http://repo.huaweicloud.com/ubuntu jammy-updates multiverse## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://repo.huaweicloud.com/ubuntu jammy-backports main restricted universe multiverse
# deb-src http://repo.huaweicloud.com/ubuntu jammy-backports main restricted uni verse multiversedeb http://repo.huaweicloud.com/ubuntu jammy-security main restricted
# deb-src http://repo.huaweicloud.com/ubuntu jammy-security main restricted
deb http://repo.huaweicloud.com/ubuntu jammy-security universe
# deb-src http://repo.huaweicloud.com/ubuntu jammy-security universe
deb http://repo.huaweicloud.com/ubuntu jammy-security multiverse
# deb-src http://repo.huaweicloud.com/ubuntu jammy-security multiverse
编译环境依赖配置
sudo apt-get install libncurses5:i386 libstdc++6:i386 zlib1g:i386 libc6:i386
// 32位兼容依赖库
//使用网络配置工具和 menuconfig 时还需要安装以下库:
linx@ubuntu:~$ sudo apt-get update //更新下载源信息
linx@ubuntu:~$ sudo apt-get install net-tools //网络配置工具sudo apt-get install lzop // 安装 lzop 工具,用于生成压缩或解压镜像
sudo apt-get install libncurses* // 安装 ncurese 相关库,U-boot 或者内核菜单显示时需要//安装一些三方开源库需要
sudo apt-get install -y autoconf automake libtool
sudo apt-get install autoconf-archive
sudo apt-get install m4sudo 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即可。
内容修改:
[Paths]
Prefix=/usr
HostPrefix=/home/t507/tmp/OKT507/err_OKT507_buildroot/OKT507-linux-sdk/out/t507/okt507/longan/buildroot/host
Sysroot=/home/t507/tmp/OKT507/err_OKT507_buildroot/OKT507-linux-sdk/out/t507/okt507/longan/buildroot/host/aarch64-buildroot-linux-gnu/sysroot
Headers=/usr/include/qt5
Plugins=/usr/lib/qt/plugins
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脚本内容如下:
#!/bin/sh
#
if [ "$#" -ne 0 ]; thenecho "Run this script to relocate the buildroot SDK at that location"exit 1
fiLOCFILE="share/buildroot/sdk-location"
FILEPATH="$(readlink -f "$0")"
NEWPATH="$(dirname "${FILEPATH}")"LICHEE_BR_OUT="/opt/okt507/buildroot"
LICHEE_OUT_DIR="/opt/okt507/buildroot"cd "${NEWPATH}"
if [ ! -r "${LOCFILE}" ]; thenecho "Previous location of the buildroot SDK not found!"exit 1
fi
OLDPATH="$(cat "${LOCFILE}")"#if [ "${NEWPATH}" = "${OLDPATH}" ]; then
# echo "This buildroot SDK has already been relocated!"
# exit 0
#fiFIX_LIST="
aarch64-linux-gnu-addr2line \
aarch64-linux-gnu-ar \
aarch64-linux-gnu-as \
aarch64-linux-gnu-c++ \
aarch64-linux-gnu-c++filt \
aarch64-linux-gnu-cpp \
aarch64-linux-gnu-dwp \
aarch64-linux-gnu-elfedit \
aarch64-linux-gnu-g++ \
aarch64-linux-gnu-gcc \
aarch64-linux-gnu-gcc-7.4.1 \
aarch64-linux-gnu-gcc-ar \
aarch64-linux-gnu-gcc-nm \
aarch64-linux-gnu-gcc-ranlib \
aarch64-linux-gnu-gcov \
aarch64-linux-gnu-gcov-dump \
aarch64-linux-gnu-gcov-tool \
aarch64-linux-gnu-gdb \
aarch64-linux-gnu-gdb-add-index \
aarch64-linux-gnu-gfortran \
aarch64-linux-gnu-gprof \
aarch64-linux-gnu-ld \
aarch64-linux-gnu-ld.bfd \
aarch64-linux-gnu-ld.gold \
aarch64-linux-gnu-nm \
aarch64-linux-gnu-objcopy \
aarch64-linux-gnu-objdump \
aarch64-linux-gnu-ranlib \
aarch64-linux-gnu-readelf \
aarch64-linux-gnu-size \
aarch64-linux-gnu-strings \
aarch64-linux-gnu-strip
"for str in $FIX_LIST
dorm bin/$strln -s $LICHEE_OUT_DIR/gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu/bin/$str $LICHEE_BR_OUT/host/bin/$str
done[ -L $LICHEE_BR_OUT/staging ] && rm $LICHEE_BR_OUT/staging
ln -s $LICHEE_BR_OUT/host/aarch64-buildroot-linux-gnu/sysroot $LICHEE_BR_OUT/staging# Check if the path substitution does work properly, e.g. a tree
# "/a/b/c" copied into "/a/b/c/a/b/c/" would not be allowed.
newpath="$(sed -e "s|${OLDPATH}|${NEWPATH}|g" "${LOCFILE}")"
if [ "${NEWPATH}" != "${newpath}" ]; thenecho "Something went wrong with substituting the path!"echo "Please choose another location for your SDK!"exit 1
fiecho "Relocating the buildroot SDK from ${OLDPATH} to ${NEWPATH} ..."# Make sure file uses the right language
export LC_ALL=C
# Replace the old path with the new one in all text files
grep -lr "${OLDPATH}" . | while read -r FILE ; doif file -b --mime-type "${FILE}" | grep -q '^text/' && [ "${FILE}" != "${LOCFILE}" ]thensed -i "s|${OLDPATH}|${NEWPATH}|g" "${FILE}"fi
done# At the very end, we update the location file to not break the
# SDK if this script gets interruted.
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