About this project
Cosmopolitan Libc is a C library and toolchain that makes C/C++ behave like a build-once run-anywhere language, similar in spirit to Java but without requiring an interpreter or virtual machine. It reconfigures stock GCC and Clang to produce a POSIX-approved polyglot executable format that runs natively across Linux, macOS, Windows, FreeBSD, OpenBSD 7.3, NetBSD and BIOS, aiming for strong performance and a very small footprint.
Getting started centers on the cosmocc compiler, distributed as a zip from cosmo.zip. After unpacking, a simple hello.c can be compiled with `cosmocc -o hello hello.c` and run directly. The runtime links heavyweight troubleshooting features by default: `--strace` logs system calls and `--ftrace` logs function calls, both using the kprintf facility, which can be redirected to a file via the KPRINTF_LOG environment variable.
The toolchain can also build conventional autotools-based open source projects by exporting CC and CXX to the cosmo compilers and running configure, make and make install. Cosmopolitan itself can be built from source on supported platforms; the Makefile downloads cosmocc automatically. Installing a systemwide APE Loader via ape/apeinstall.sh is recommended, and on Linux it registers with binfmt_misc for extra performance. Builds use GNU Make, with a bootstrap make available from cosmo.zip. Because the repository is large, individual targets can be built, such as a single POSIX test or an entire test package. Build modes include `m=tiny` for very small binaries (as small as 12kb) and `m=tinylinux` to trim other operating systems and behave more like Musl Libc.
Debugging guidance covers GDB configuration for UTF-8 charsets and layouts, running .dbg files, and loading debug symbols independently. Platform notes address shells (zsh 5.9+ recommended, with workarounds for older shells and Python subprocess), Linux systems that misroute MZ executables to WINE or print run-detector errors, and WSL, where disabling WSLInterop binfmt_misc is advised. The project lists minimum supported platform versions, including AMD K8, Intel Core, Linux 2.6.18, Windows 8 (with a community vista branch for older Windows), Darwin 23.1.0+, OpenBSD 7.3, FreeBSD 13 and NetBSD 9.2. Development discussion happens on a Discord server, and funding comes through GitHub Sponsors and Patreon.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.