jart/cosmopolitan logo

jart/cosmopolitan

Free

build-once run-anywhere c library

FreeFree tier
Type
Open Source

About jart/cosmopolitan

Cosmopolitan Libc is a C library that makes C and C++ a build-once run-anywhere language, similar to Java but without needing an interpreter or virtual machine. It reconfigures stock GCC and Clang to output a POSIX-approved polyglot format that runs natively on Linux, macOS, Windows, FreeBSD, OpenBSD 7.3, NetBSD, and BIOS. It offers the best possible performance and the tiniest footprint. The project provides a compiler toolchain (cosmocc) available at cosmo.zip and supports building conventional open source projects using autotools. Includes troubleshooting features like system call logging (--strace) and function call logging (--ftrace).

Key Features

Build-once run-anywhere polyglot format
Runs natively on Linux, macOS, Windows, FreeBSD, OpenBSD 7.3, NetBSD, and BIOS
No interpreter or virtual machine required
Reconfigures stock GCC and Clang compilers
Includes cosmocc compiler toolchain
Supports autotools-based project builds
System call tracing (--strace) and function call tracing (--ftrace)
APE Loader for system-wide installation
Small footprint and high performance

Pros & Cons

Pros
  • Truly portable across diverse operating systems without a virtual machine
  • High performance and minimal footprint
  • Uses standard compilers (GCC/Clang) with custom configuration
  • Built-in troubleshooting tools for system and function call tracing
  • Supports existing autotools-based projects with minimal adaptation
Cons
  • Requires downloading the separate cosmocc compiler toolchain to get started

Best For

Building cross-platform C/C++ applications that run on multiple operating systemsCreating portable executables for Linux, macOS, Windows, BSDs, and BIOSDeveloping system-level software with minimal dependencies and high performance

FAQ

What operating systems does Cosmopolitan support?
Cosmopolitan runs natively on Linux, macOS, Windows, FreeBSD, OpenBSD 7.3, NetBSD, and BIOS.
How do I compile a program with Cosmopolitan?
Download the cosmocc compiler from cosmo.zip, then use the command: cosmocc -o hello hello.c
Does Cosmopolitan require a virtual machine or interpreter?
No, it produces a POSIX-approved polyglot binary that runs directly on the supported platforms without any VM or interpreter.