Backgrounds
In most cases, we now use QEMU technology to run ARM containers on X86 platforms, employing these containers as cross-compilation tools. However, due to the different instruction set architectures between the host environment and the Docker environment, compilation speeds are slow. To address this issue, we can directly use an ARM cross-compiler toolchain on the X86 host. During the development of large projects, when you need to link a large number of third-party libraries, the compiler will alert you of link errors and other issues.
How
My development environment requires Ubuntu 22.04, so the rootfs I am using is Ubuntu 22.04. If you want to use a different version, you can modify the script according to your own situation.
Install the cross-compilation toolchain
1 | sudo apt update |
Build a cross-compilation environment rootfs
1 | git clone https://github.com/kaylorchen/rk3588_dev_rootfs.git |
Compile your code using the cross-compilation environment
Following the steps above, a file named “toolchain-aarch64.cmake” will be generated in the current directory. You will need to use it in your CMake project.
For example:1
2
3
4mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=/opt/data/orangepi/rk3588_dev_rootfs/toolchain-aarch64.cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
make
/opt/data/orangepi/rk3588_dev_rootfs/toolchain-aarch64.cmake is an absolute path
Update your rootfs
When we compile code, sometimes we find that some dependency packages are missing. We need to update our rootfs.
edit config.sh, add a new package named “aaa”:
1
2
3
4
5
6
apt update
apt install -y --no-install-recommends vim libopencv-dev g++ gcc \
fakeroot devscripts libspdlog-dev libsystemd-dev libcap-dev liblz4-dev \
libgcrypt-dev libzstd-dev debhelper rknpu2-dev librockchip-mpp-dev librga-dev \
libstb-dev libturbojpeg0-dev libjpeg-turbo8-dev kaylordut-dev aaaupdate rootfs
1
./update.sh