cosmopolitan
build-once run-anywhere c library
Cosmopolitan Libc lets you compile a C or C++ program once and run the resulting binary natively on Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD, and BIOS, no virtual machine or per-platform build toolchain needed. It works by producing a special Actually Portable Executable format using standard
Cosmopolitan Libc is a C library that lets you compile a C or C++ program once and have the resulting binary run natively on Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD, and even BIOS without needing a virtual machine or interpreter. It achieves this by configuring standard compilers (GCC and Clang) to output a special file format called an Actually Portable Executable (APE) — a POSIX-approved polyglot format that each operating system can understand and run directly.
The key value proposition is eliminating the "build once per target platform" problem. Normally, if you want a C program to run on both Linux and Windows, you need separate build toolchains and outputs for each. Cosmopolitan produces a single binary that works everywhere. The project ships its own compiler wrapper called cosmocc, which developers use in place of a standard C compiler. Existing open-source projects that use the autotools build system can often be compiled with Cosmopolitan with minimal changes.
Built-in debugging aids include --strace (logs system calls) and --ftrace (logs function call traces) flags that any Cosmopolitan program can accept at runtime. The project supports x86-64 hardware and is crowdfunded through GitHub Sponsors and Patreon.
Where it fits
- Ship a C command-line tool as a single binary that works on Linux, macOS, and Windows without separate per-platform builds.
- Port an existing autotools C project to all major operating systems by compiling with the cosmocc wrapper instead of a standard compiler.
- Debug a cross-platform C program using built-in runtime flags for system call and function call tracing without installing extra tools.