Using cross-compilation for ARM64 in the Ubuntu 24.04 x86 environment
-
I would like to ask if my setup is correct. Why does the file not change to ARM64 after running cmake --install . ?
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu $ which aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc $ aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
After verifying the cross-compilation tool, enter the Qt/6.8.2/ directory, create a folder, and start compiling.
cd ./Qt/6.8.2/ mkdir arm64 mkdir build && cd build ../Src/configure -prefix /home/ptc/Qt/6.8.2/arm64 -platform linux-g++ -device linux-aarch64-gnu-g++ -device-option CROSS_COMPILE=aarch64-linux-gnu- -no-opengl -make libs
Using the file command to check the file, it is still x86.
$ file /home/ptc/Qt/6.8.2/arm64/lib/libQt6Quick.so.6.8.2 /home/ptc/Qt/6.8.2/arm64/lib/libQt6Quick.so.6.8.2: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=98b91422f304c376f1f70edb73b6276205a6027b, not stripped
It also cannot be executed on Qt Creator.
I would like to ask how I can resolve this issue. I would greatly appreciate it.
-
I have already resolved the issue and successfully cross-compiled for arm64 on Ubuntu 24.04 x86 using Qt6.8.2.
I will provide my method.
The configure command is as follows:../Src/configure \ -prefix /home/ptc/Qt/6.8.2/arm64 \ -qt-host-path /home/ptc/Qt/6.8.2/gcc_64 \ -platform linux-g++ \ -device linux-aarch64-gnu-g++ \ -device-option CROSS_COMPILE=aarch64-linux-gnu- \ -no-opengl \ -skip qtopcua -skip qtwebengine -skip qtwebview -skip qtserialport -skip qtlocation \ -no-feature-brotli -no-feature-hunspell \ -- -DCMAKE_TOOLCHAIN_FILE=$HOME/Qt/6.8.2/toolchain/arm64-toolchain.cmake
Before this, create a new toolchain.cmake file yourself.
set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc") set(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++") set(CMAKE_LINKER "/usr/bin/aarch64-linux-gnu-ld") set(CMAKE_AR "/usr/bin/aarch64-linux-gnu-ar") set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Next, you can follow my method to add the arm64-related dependencies on x86.
$ sudo dpkg --add-architecture arm64 $ sudo vim /etc/apt/sources.list.d/ubuntu-arm64.sources Types: deb URIs: http://ports.ubuntu.com/ubuntu-ports/ Suites: noble noble-updates noble-security Components: main restricted universe multiverse Architectures: arm64 Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg $ sudo apt update $ sudo apt install -y libudev-dev:arm64 libmtdev-dev:arm64
Finally, execute the configure command.
-
@Steven-LIN Please don't double post.
This is same as https://forum.qt.io/topic/161304/using-cross-compilation-for-arm64-in-the-ubuntu-24-04-x86-environment?_=1741068261682 -
I have already resolved the issue and successfully cross-compiled for arm64 on Ubuntu 24.04 x86 using Qt6.8.2.
I will provide my method.
The configure command is as follows:../Src/configure \ -prefix /home/ptc/Qt/6.8.2/arm64 \ -qt-host-path /home/ptc/Qt/6.8.2/gcc_64 \ -platform linux-g++ \ -device linux-aarch64-gnu-g++ \ -device-option CROSS_COMPILE=aarch64-linux-gnu- \ -no-opengl \ -skip qtopcua -skip qtwebengine -skip qtwebview -skip qtserialport -skip qtlocation \ -no-feature-brotli -no-feature-hunspell \ -- -DCMAKE_TOOLCHAIN_FILE=$HOME/Qt/6.8.2/toolchain/arm64-toolchain.cmake
Before this, create a new toolchain.cmake file yourself.
set(CMAKE_SYSTEM_NAME Linux) set(CMAKE_SYSTEM_PROCESSOR aarch64) set(CMAKE_C_COMPILER "/usr/bin/aarch64-linux-gnu-gcc") set(CMAKE_CXX_COMPILER "/usr/bin/aarch64-linux-gnu-g++") set(CMAKE_LINKER "/usr/bin/aarch64-linux-gnu-ld") set(CMAKE_AR "/usr/bin/aarch64-linux-gnu-ar") set(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Next, you can follow my method to add the arm64-related dependencies on x86.
$ sudo dpkg --add-architecture arm64 $ sudo vim /etc/apt/sources.list.d/ubuntu-arm64.sources Types: deb URIs: http://ports.ubuntu.com/ubuntu-ports/ Suites: noble noble-updates noble-security Components: main restricted universe multiverse Architectures: arm64 Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg $ sudo apt update $ sudo apt install -y libudev-dev:arm64 libmtdev-dev:arm64
Finally, execute the configure command.
-