explaingit

jart/cosmopolitan

📈 Trending20,822CAudience · developerComplexity · 4/5ActiveLicenseSetup · easy

TLDR

A C library that compiles once and runs natively on Linux, macOS, Windows, FreeBSD, and other OSes without recompilation or virtual machines.

Mindmap

mindmap
  root((Cosmopolitan))
    What it does
      Single binary
      Multiple OS support
      No recompilation
    How it works
      APE format
      GCC/Clang wrapper
      cosmocc compiler
    Use cases
      Cross-platform tools
      Portable utilities
      Embedded systems
    Tech stack
      C language
      x86-64 hardware
      POSIX standard
    Developer tools
      Strace debugging
      Ftrace tracing
      Autotools support

Things people build with this

USE CASE 1

Build command-line tools that work on Linux, macOS, and Windows from a single codebase.

USE CASE 2

Distribute portable utilities to users without requiring them to install dependencies or use containers.

USE CASE 3

Compile existing open-source C projects to run across multiple operating systems with minimal code changes.

Tech stack

CC++GCCClangx86-64POSIX

Getting it running

Difficulty · easy Time to first run · 5min
Cosmopolitan is released under the ISC license, allowing free use for any purpose including commercial, with attribution.

In plain English

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.

Copy-paste prompts

Prompt 1
How do I use cosmocc to compile my C program so it runs on both Linux and Windows?
Prompt 2
Show me how to add --strace and --ftrace debugging to a Cosmopolitan program at runtime.
Prompt 3
Can I compile an autotools-based open-source project with Cosmopolitan, and what changes do I need to make?
Prompt 4
What is an Actually Portable Executable (APE) and how does it let one binary run on multiple operating systems?
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.