Repolode
jart

jart/cosmopolitan

A C standard library and toolchain setup that builds one executable that runs natively on Linux, macOS, Windows, BSDs and BIOS.

Stars
21,434
Forks
785
Open issues
226
Last commit
18 days ago

What is it?

Cosmopolitan Libc lets C and C++ programs be built once and run on Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD and BIOS. It reconfigures stock GCC and Clang to emit a polyglot executable format called Actually Portable Executable (APE), so no interpreter or virtual machine is needed.

The project provides the cosmocc compiler distribution, which is used like a normal C compiler, and can also be used to build existing autotools-based open source projects. The runtime includes built-in tracing options such as --strace and --ftrace for debugging system and function calls.

The repository also contains a source build system with build modes such as tiny and tinylinux for smaller binaries, plus notes on platform setup for APE loading on Linux and WSL.

Key features

  • 01Builds C and C++ programs into single executables that run on multiple operating systems.
  • 02Works with stock GCC and Clang toolchains through the cosmocc distribution.
  • 03Includes --strace and --ftrace runtime options for debugging.
  • 04Offers build modes such as tiny and tinylinux for smaller binaries.
  • 05Supports building autotools-based open source projects.

Use cases

  • Distributing a command-line tool as one file that works on Linux, macOS and Windows.
  • Packaging portable utilities or servers for systems without a runtime installed.
  • Building existing C projects for multiple operating systems without per-platform builds.

Quick start

  1. 1

    Download the cosmocc compiler release

    wget https://cosmo.zip/pub/cosmocc/cosmocc.zip
  2. 2

    Unzip the compiler archive

    unzip cosmocc.zip
  3. 3

    Compile a hello world program

    cosmocc -o hello hello.c
  4. 4

    Run the resulting executable

    ./hello

Things to know

  • On some Linux distros, APE programs fail until you register the APE loader with binfmt_misc.
  • Running APE programs under WSL is unsafe unless you disable WSLInterop, and Windows 7 and Vista need a separate community branch.

In collections

Topics

#libc#compiler#cross-platform#portable-executable#toolchain#bios#containers#darwin#efi#freebsd

FAQ

What is cosmopolitan?
A C standard library and toolchain setup that builds one executable that runs natively on Linux, macOS, Windows, BSDs and BIOS. Cosmopolitan Libc lets C and C++ programs be built once and run on Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD and BIOS. It reconfigures stock GCC and Clang to emit a polyglot executable format called Actually Portable Executable (APE), so no interpreter or virtual machine is needed.
Is cosmopolitan free to use? What license does it have?
cosmopolitan is open source under the ISC license. Check the license terms before using it in commercial products.
Is cosmopolitan still maintained?
Actively maintained. The last commit to cosmopolitan was on Oct 20, 2026.
What can I use cosmopolitan for?
Distributing a command-line tool as one file that works on Linux, macOS and Windows. Packaging portable utilities or servers for systems without a runtime installed. Building existing C projects for multiple operating systems without per-platform builds.
How do I install cosmopolitan?
Download the cosmocc compiler release: wget https://cosmo.zip/pub/cosmocc/cosmocc.zip Unzip the compiler archive: unzip cosmocc.zip Compile a hello world program: cosmocc -o hello hello.c Run the resulting executable: ./hello
Where can I get cosmopolitan?
The source code and installation instructions are on GitHub: https://github.com/jart/cosmopolitan

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects