Background: Since recent projects require domestic system adaptation, a lot of software needs to be recompiled to adapt to CPUs of different architectures.
environment:
1. Host win10 64bit vmware virtual host ubuntu1804 64bit
2. The vmware virtual host has installed qt5.14.2 and qt_create4.11.1
1. Cross-compilation of C/C++ programs
1. Cross-compilation environment construction
①Select the compilation tool aarch64-linux-gnu
②Install cross-compilation tools
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
After installation, verify whether it is ok. Directly enter aarch64- and press the Tab key. If it can automatically complete aarch64-linux-gnu-gcc, then there is no problem. Check the version information: aarch64-linux-gnu-gcc -v, you can find the following As shown in the figure, the installation is complete.
aarch64-linux-gnu-gcc -v
2. Compile source code
For example, you need to compile the test.c source code into an arm64 executable file. The instructions are as follows:
aarch64-linux-gnu-gcc -o test test.c
After the compilation is passed, use the file command to check whether the file type is ELF: 64bit LSB shared object, ARM aarch64... If so, the source code compilation is completed.
3. QT builds arm64 compilation environment
①Download qt-everywhere-src-5.14.2.tar.xz, and use the xz command to decompress the qt-everywhere-src-5.14.2.tar file, and then use the tar command to decompress qt-everywhere-src-5.14.2. tar file and get the folder: qt-everywhere-src-5.14.2
xz -d qt-everywhere-src-5.14.2.tar.xz
tar -xvf qt-everywhere-src-5.14.2.tar
Check whether the compiler in the linux-aarch64-gnu-g++/qmake.conf configuration file in qt-everywhere-src-5.14.2/qtbase/mkspecs is aarch64-linux-gnu- If not, it needs to be modified to the corresponding cross-compilation Tool name, as shown below:
②Enter the source code root directory: cd qt-everywhere-src-5.14.2
./configure -prefix /opt/Qt5.14.2/5.14.2/aarch64 -make libs -xplatform linux-aarch64-gnu-g++ -no-opengl -skip qtdeclarative
illustrate:
- no-opengl is because the interface version of qt has been installed before
-skip qtdeclarative is a compilation problem and is temporarily skipped.
③Compile make -j16 2>&1 | tee build.log. Note that some lisence options will be entered during compilation. Just choose open source.
④Installation
Because the path specified during configuration is /opt/Qt5.14.2/5.14.2/aarch64, you need to create the aarch64 folder first and then install it. After the installation is completed, the corresponding folder will be generated in the /opt/Qt5.14.2/5.14.2/aarch64 path.
sudo mkdir -p /opt/Qt5.14.2/5.14.2/aarch64
sudo make install
⑤QT configuration option modification
After Compliers has installed the cross-compilation tool, the system can automatically find it. If it cannot be found, you need to add it yourself through the Add button.
Qt Versions needs to add a customized version, qmake needs the newly compiled and installed qmake
Kits need to select their newly added Qt Version
⑥Project creation and compilation
Once the above preparations are ready, you can open or create a new QT project. To build and run, select aarch64 to build the project. Compile to obtain the QT application required by arm64, provide a guide to the arm64 host, and run tests.