cross-gcc

Guide GCC cross-compilation toolchain setup and QEMU testing of binaries.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/awfixers-stuff/opencode-config --skill cross-gcc-awfixers-stuff
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cross-gcc
Source: https://github.com/awfixers-stuff/opencode-config/tree/main/skills/cross-gcc
Command: npx skills add https://github.com/awfixers-stuff/opencode-config --skill cross-gcc-awfixers-stuff

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers and build engineers cross-compile software with GCC by explaining triplets, installing and selecting appropriate cross-compilers, configuring sysroots and pkg-config for target libraries, and validating or debugging cross-compiled binaries under QEMU so builds work reliably across host and target architectures.

Core Features & Use Cases

  • Triplet and toolchain guidance: identify and choose triplets like aarch64-linux-gnu, arm-none-eabi, riscv64-linux-gnu and install matching gcc/g++ and binutils packages.
  • Sysroot and pkg-config configuration: create or use a sysroot, set PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR, and avoid linking against host libraries.
  • CMake and build integration: provide a minimal CMake toolchain file pattern and flags to find target includes and libraries.
  • Testing and debugging: run user-mode QEMU for quick execution, set up binfmt_misc for transparency, and perform remote GDB debugging with qemu -g and target remote.
  • Troubleshooting: diagnose common errors such as wrong ELF class, missing -lfoo during link, ABI runtime issues, and relocation or opcode mismatches.

Quick Start

Use the cross-gcc skill to set up an aarch64-linux-gnu toolchain, point CMAKE_SYSROOT or --sysroot to a target sysroot, build a simple hello program with aarch64-linux-gnu-gcc, and run it under qemu-aarch64-static to verify execution.

Frequently Asked Questions about cross-gcc

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up a GCC cross-compilation toolchain for ARM or RISC-V targets?

To set up a GCC cross-compilation toolchain, identify the target triplet like aarch64-linux-gnu or riscv64-linux-gnu, install the matching gcc, g++, and binutils packages, and configure your build system to use the resulting cross-compiler binaries for targeting ARM, AArch64, RISC-V, MIPS, or Windows from an x86_64 host.

Why does cross-compilation fail with wrong ELF class or missing host libraries?

Cross-compilation fails with wrong ELF class or missing library errors when pkg-config and the linker reference host libraries instead of target libraries, which you fix by configuring a proper sysroot and setting PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_LIBDIR to isolate target dependencies.

How do I configure CMake to use a cross-compile sysroot and pkg-config?

Configure CMake for cross-compilation by writing a minimal CMake toolchain file that sets CMAKE_SYSROOT and compiler flags, ensuring CMake finds target includes and libraries while preventing pkg-config from resolving incorrect host paths.

What is the best way to test cross-compiled binaries for a different architecture?

The best way to test cross-compiled binaries is using QEMU user-mode execution, running the target binary directly on your x86_64 host and optionally setting up binfmt_misc for transparent execution or using qemu -g for remote GDB debugging.

Can I cross-compile for Windows targets using a GCC toolchain on an x86_64 host?

Yes, you can cross-compile for Windows targets from an x86_64 host by selecting the appropriate Windows triplet, installing the matching GCC cross-compiler packages, and configuring your build environment to locate the correct target sysroot and libraries.

When do I need a sysroot for cross-compiling software with GCC?

You need a sysroot for cross-compiling software with GCC whenever your project depends on target-specific libraries, requiring you to set the sysroot path so the compiler and pkg-config locate target headers and shared objects instead of host system libraries.