Cross-GCC
Purpose
Guide agents through setting up and using cross-compilation GCC toolchains: triplets, sysroots, pkg-config, QEMU-based testing, and common failure modes.
Triggers
- "How do I compile for ARM on my x86 machine?"
- "I'm getting 'wrong ELF class' or 'cannot execute binary file'"
- "How do I set up a sysroot for cross-compilation?"
- "pkg-config returns host libraries in my cross build"
- "How do I debug a cross-compiled binary with QEMU + GDB?"
Workflow
1. Understand the triplet
A GNU triplet has the form <arch>-<vendor>-<os>-<abi> (often 3 or 4 parts):
2. Install the toolchain
3. Basic cross-compilation
4. Sysroot
A sysroot is a directory containing the target's headers and libraries. Required when your code links against target-specific libraries.
Verify the sysroot is correct:
5. pkg-config for cross builds
pkg-config will return host library paths by default. Override:
6. CMake cross-compilation
Create a toolchain file aarch64.cmake:
7. Test with QEMU
8. Common errors
9. Environment variables
For a reference on ARM-specific GCC flags, see references/arm-flags.md [blocked].
Related skills
- Use
skills/compilers/gccfor GCC flag details - Use
skills/debuggers/gdbfor remote debugging withgdbserver - Use
skills/low-level-programming/assembly-armfor AArch64 assembly specifics - Use
skills/build-systems/cmakefor toolchain file setup


