TinyCC supports cross-compilation for multiple target architectures, allowing you to build executables for different platforms from a single development environment.
Supported architectures
TinyCC can cross-compile for the following target architectures:
i386 - 32-bit x86 (Linux, Windows)
x86_64 - 64-bit x86 (Linux, Windows, macOS)
ARM - 32-bit ARM (Linux, Windows CE)
ARM64 - 64-bit ARM/AArch64 (Linux, macOS, BSD)
RISC-V 64 - 64-bit RISC-V (Linux)
Cross-compilation support varies by host platform. Not all target architectures can be built from all host systems.
Building cross-compilers
Enable cross-compilation during configuration
When configuring TinyCC, enable cross-compiler builds: ./configure --enable-cross
This enables building all supported cross-compilers.
Build all cross-compilers
Build all cross-compilers and their runtime libraries: This creates executables like i386-tcc, x86_64-tcc, arm-tcc, arm64-tcc, and riscv64-tcc.
Build specific cross-compiler (optional)
To build only a specific cross-compiler: make cross-x86_64
make cross-arm64
make cross-riscv64
Install cross-compilers
Install the cross-compilers to your system:
Using cross-compilers
Basic cross-compilation
Use the architecture-specific TCC binary to cross-compile:
# Compile for x86_64 Linux
x86_64-tcc -o program program.c
# Compile for ARM Linux
arm-tcc -o program program.c
# Compile for ARM64 Linux
arm64-tcc -o program program.c
Target-specific switches
# Cross-compile for 64-bit x86 (from 32-bit host)
tcc -m64 -o program program.c
Windows (PE) executables
Cross-compile Windows executables from Linux:
# 32-bit Windows executable
i386-win32-tcc -o hello.exe hello.c
# 64-bit Windows executable
x86_64-win32-tcc -o hello.exe hello.c
# Windows DLL
i386-win32-tcc -shared -o mylib.dll mylib.c
macOS (Mach-O) executables
Cross-compile macOS binaries:
# 64-bit x86 macOS
x86_64-osx-tcc -o program program.c
# ARM64 macOS (Apple Silicon)
arm64-osx-tcc -o program program.c
Linux
Android
Windows CE
BSD
# Standard ARM Linux
arm-tcc -o program program.c
# ARM64 Linux
arm64-tcc -o program program.c
Configuration options
System root and include paths
Specify custom system root and library paths for cross-compilation:
./configure \
--cpu=arm64 \
--cross-prefix=aarch64-linux-gnu- \
--sysroot=/usr/aarch64-linux-gnu \
--sysincludepaths=/usr/aarch64-linux-gnu/include \
--libpaths=/usr/aarch64-linux-gnu/lib \
--crtprefix=/usr/aarch64-linux-gnu/lib
Triplet configuration
Set the target triplet for library and include directory detection:
./configure \
--cpu=x86_64 \
--triplet=x86_64-linux-gnu
./configure \
--cpu=arm \
--triplet=arm-linux-gnueabihf
The triplet configuration helps TCC automatically locate system libraries and headers in multiarch systems.
Runtime library (libtcc1.a)
Each cross-compiler requires its own runtime library:
# Build runtime for specific target
make arm64-libtcc1.a
make x86_64-libtcc1.a
make riscv64-libtcc1.a
# Runtime libraries are automatically built with 'make cross'
The runtime library provides:
Integer division and modulo operations
64-bit integer operations on 32-bit platforms
Floating-point operations
Memory operations (memset, memcpy)
Limitations
Cross-compilation limitations :
Host and target endianness must match (big-endian to big-endian, little-endian to little-endian)
Position-independent code (PIC) for shared libraries may have limitations on some targets
Some platform-specific features may require native compilation
Windows cross-compilation from Linux requires mingw headers
Advanced cross-compilation
Custom cross-compiler configuration
Create config-extra.mak to customize cross-compiler paths:
# Custom ARM64 configuration
ROOT-arm64 = /usr/aarch64-linux-gnu
CRT-arm64 = {R}/lib
LIB-arm64 = {B}:{R}/lib
INC-arm64 = {B}/include:{R}/include
DEF-arm64 += -D__linux__
# Custom RISC-V configuration
TRIPLET-riscv64 = riscv64-linux-gnu
ROOT-riscv64 = /usr/riscv64-linux-gnu
TCC replaces {B} with the TCC directory and {R} with CONFIG_SYSROOT.
Multiple target builds
Build for multiple targets in sequence:
# Build for multiple architectures
for arch in i386 x86_64 arm arm64 riscv64 ; do
${ arch } -tcc -o program- ${ arch } program.c
done
Troubleshooting
If cross-compilation fails due to missing headers:
# Install multiarch support (Debian/Ubuntu)
sudo apt-get install gcc-arm-linux-gnueabihf
sudo apt-get install gcc-aarch64-linux-gnu
sudo apt-get install gcc-riscv64-linux-gnu
# Install mingw for Windows cross-compilation
sudo apt-get install mingw-w64
Testing cross-compiled binaries
Test cross-compiled binaries using QEMU:
# Install QEMU user-mode emulation
sudo apt-get install qemu-user
# Run ARM binary
qemu-arm -L /usr/arm-linux-gnueabihf ./program-arm
# Run ARM64 binary
qemu-aarch64 -L /usr/aarch64-linux-gnu ./program-arm64
# Run RISC-V binary
qemu-riscv64 -L /usr/riscv64-linux-gnu ./program-riscv64
See also