Cosmopolitan Libc: build-anywhere run-anywhere C library

submited by
Style Pass
2025-01-24 23:00:06

Cosmopolitan Libc makes C a build-anywhere run-anywhere language, like Java, except it doesn't need an interpreter or virtual machine. Instead, it reconfigures stock GCC and Clang to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS on AMD64 and ARM64 with the best possible performance. Getting Started

First, download the Cosmopolitan toolchain: mkdir cosmocc cd cosmocc wget https://cosmo.zip/pub/cosmocc/cosmocc.zip unzip cosmocc.zip Sanity Test

If you get "zsh: exec format error" then you need to upgrade to zsh 5.9+ (we patched it 2 years ago). The same goes for Fish.

Linux users will want to install APE Loader. This will solve issues like WINE trying to run APE, or "run-detectors: unable to find an interpreter". # for linux users sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf sudo chmod +x /usr/bin/ape sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"

If you're on Windows, try renaming bin/make to bin/make.exe and run that. Then rename it back. Since cosmocc is a shell script, you need a UNIX shell. You can get programs like bash, less, etc. by downloading Cosmos programs and putting them in C:\bin. ProTip: dash makes a pretty good C:\bin\sh (which in cosmo speak is /bin/sh or /c/bin/sh). Next, install Terminal Preview from the Windows Store and configure it so that C:\bin\bash -l is your shell. That way, the lack of a .exe extension will no longer be an issue.

Leave a Comment