How to Cross-Compile libaom for ARM?
Cross-compiling libaom (the Alliance for Open Media AV1
codec library) for ARM architectures allows you to build efficient video
encoding and decoding software for embedded devices, smartphones, and
Raspberry Pi boards from a standard x86_64 host machine. This process
requires a proper toolchain, the CMake build system, and specific
configuration flags to target the correct ARM architecture (such as
ARMv7 or AArch64). By configuring the build environment correctly, you
can generate optimized binaries tailored for your target hardware.
Prerequisites and Toolchain Setup
Before starting, you need a host system (typically Linux x86_64) equipped with the necessary cross-compiler. For ARM architectures, the GNU Toolchain is the standard choice.
- For 64-bit ARM (AArch64/ARM64): Install
aarch64-linux-gnu-gccandaarch64-linux-gnu-g++. - For 32-bit ARM (ARMv7/HF): Install
arm-linux-gnueabihf-gccandarm-linux-gnueabihf-g++. - Build Tools: Ensure
cmake,make(orninja), andgitare installed on your host system.
On Debian or Ubuntu-based systems, you can install these via apt:
sudo apt update
sudo apt install git cmake ninja-build gcc-aarch64-linux-gnu g++-aarch64-linux-gnuFetching the libaom Source Code
Clone the official libaom repository from the Alliance
for Open Media Git server and navigate into the directory:
git clone https://aomedia.googlesource.com/aom
cd aomConfiguring CMake for ARM Cross-Compilation
libaom uses CMake toolchain files to handle
cross-compilation. The repository includes pre-configured toolchain
files for common architectures inside the
build/cmake/toolchains/ directory.
Create a separate build directory to keep the source tree clean:
mkdir build_arm64 && cd build_arm64Execute the CMake command, pointing to the appropriate toolchain file. For a 64-bit ARM target using Ninja as the generator, run:
cmake .. \
-G Ninja \
-DCMAKE_TOOLCHAIN_FILE=../build/cmake/toolchains/arm64-linux-gcc.cmake \
-DCONFIG_RUNTIME_CPU_DETECT=0 \
-DENABLE_DOCS=OFF \
-DENABLE_EXAMPLES=OFF \
-DENABLE_TESTS=OFFKey Configuration Flags
- CMAKE_TOOLCHAIN_FILE: Specifies the path to the
target architecture configuration (e.g.,
arm64-linux-gcc.cmakeorarmv7-linux-gcc.cmake). - CONFIG_RUNTIME_CPU_DETECT: Setting this to
0disables runtime CPU feature detection, hardcoding optimizations for the specified target and reducing binary size. Set to1if you need a generic binary that detects specific ARM extensions (like NEON) at runtime. - ENABLE_DOCS / EXAMPLES / TESTS: Disabling these features speeds up the compilation process significantly and prevents compilation errors related to host-run target binaries.
Compiling and Installing
Once CMake successfully generates the build files, start the compilation process:
ninjaIf you prefer standard Makefiles over Ninja, replace
-G Ninja with -G "Unix Makefiles" in the CMake
step, and run make instead.
After the build completes, compile artifacts (including
libaom.a and libaom.so) will be available in
your build directory. To install the binaries and headers to a specific
staging directory for deployment to your ARM target, use:
DESTDIR=/path/to/your/target/sysroot ninja install