QT cross-compilation environment construction for embedded linux (the simplest measured general version)

Here is a summary of the construction of the QT cross-compilation environment for embedded linux, keep it as a memo, and share it with friends in need. No matter what embedded linux environment you have, a summary of the general methods that have been tested.

Environmental preparation

The environment requirements to be prepared are as follows:

1. Virtual machine (vmvare15.5)

2. Linux system image of ubuntu18.04-x64

3.qt installation package (qt-5.12.9)

4. Cross-compilation tool chain (generally provided by manufacturers)

vmvare15.5 download

VMWare (Virtual Machine ware) is a virtual machine software that allows you to run two or more Windows, DOS, and LINUX systems on one machine at the same time.

 download link

VMware-workstation-full-15.5.0-14665864.exe_Free high-speed download|Baidu Netdisk-share unlimited

Virtual machine network settings

 NAT connection method

By default, after the virtual machine is installed, the network connection method is NAT as shown in the figure below, and it shares an IP address with the host machine. We do not need to change it when installing dependent packages and compiling code.
In the virtual machine, when the VMware virtual network card is set to NAT mode, the network in the Ubuntu environment can be set to dynamic IP. In this mode, the virtual NAT device and the host network card are connected to communicate and surf the Internet. This is the most common way for our virtual machine to access the Internet.

Bridge connection mode
When the VMware virtual network card device is in bridge mode, the host network card and the virtual machine network card communicate through the virtual network bridge. It is necessary to set the network IP in the Ubuntu environment to be on the same network segment as the host. If you need to go to the external network, you need to set DNS Consistent with the host network card. If you use TFTP, SFTP and other servers, you need to set the network connection method of the virtual machine to bridge mode.

Update the system image source

The download of the image source that comes with ubuntu18 is very slow, and it is necessary to replace the image source. It is inevitable to download and install some things online.

Backup first: cp /etc/apt/sources.list /etc/apt/sources.list.bak
and then copy the following source files to /etc/apt/sources.list

Can be opened with Vi or gedit.

Ali mirror source

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

Huawei mirror source

# 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 multiverse
 
deb 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

Compilation environment depends on configuration

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 m4
 
sudo apt install pkg-config

QT download

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

Precautions

The QT installation package can be directly downloaded from the official website on linux and installed. Such as: https://download.qt.io/archive/qt/5.12/5.12.9/qt-opensource-linux-x64-5.12.9.run

Precautions, because the ultimate purpose is to use the embedded environment of the development board. So the above is only the QT environment installed on the linux computer. In the end, cross-compilation is required before it can run on an embedded linux board. You need to determine whether your cross-compilation toolchain includes QT header files and libraries. General development board manufacturers provide a ready-made cross-compilation toolchain including QT, so there is no need to recompile the source code of QT. Open Qtcreater, just configure the cross-compiled toolchain.

The introduction in some articles is very troublesome, such as installing qtcreater and the like separately. The directly downloaded qt5.12.9 contains qt sdk and qtcreater.

Problems encountered in installing QT

Qt version is not properly installed,please run make install

1. Directly copy the QT library installed by others, and when compiling on your own computer, it prompts that Qt version is not properly installed, please run make install.

2. Find the reason from the Internet: it turns out that qmake.exe is generated when Qt is installed and compiled, and some paths related to Qt are embedded in it. If you copy it directly, your own path structure is different from the original one, and the Qt library cannot be used normally.

3. Solution: Create a new text file in the directory where qmake.exe is located, write the following content into the text file, and name the file qt.conf.
Content modification:

[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:

This error was reported because someone else's toolchain was copied from elsewhere. Then many soft links should not be found. The following script needs to be run to delete the soft link of the old toolchain and recreate a new soft link.

The content of the changeSdkLocation.sh script is as follows:

#!/bin/sh
#
if [ "$#" -ne 0 ]; then
    echo "Run this script to relocate the buildroot SDK at that location"
    exit 1
fi

LOCFILE="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}" ]; then
    echo "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
#fi

FIX_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
do
	rm bin/$str
	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
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}" ]; then
    echo "Something went wrong with substituting the path!"
    echo "Please choose another location for your SDK!"
    exit 1
fi

echo "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 ; do
    if file -b --mime-type "${FILE}" | grep -q '^text/' && [ "${FILE}" != "${LOCFILE}" ]
    then
        sed -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}

Then it reported another error: 

The reason is, gcc-linaro-7.4.1-2019.02-x86_64_aarch64-linux-gnu\libexec\gcc\aarch64-linux-gnu\7.4.1\liblto_plugin.so, the soft link is invalid, and the new soft link is under.

The problem of soft link failure is most likely caused by direct copying from windows. It is recommended to copy to the virtual machine instead of copying the folder directly. The correct approach should be to decompress.

other resources

ubuntu builds qt arm cross-compilation environment

Ubuntu20.04.1 (X86_64) Qt5.14.2 configuration ARM64 cross-compilation environment_Kwok HQ's blog-CSDN blog

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

Guess you like

Origin blog.csdn.net/qq8864/article/details/132388859