HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
jart
cosmopolitan
C2020–2026
jart / cosmopolitan

cosmopolitan

build-once run-anywhere c library

135Distinct people
293Mentions
3Explicit recommenders
21.4KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

build-once run-anywhere c library

GitHub

Where it is used

  • Blink — Blink uses Cosmopolitan Libc as the primary target for the binaries it runs. It is designed to support Cosmopolitan-built APE executables and relies on them heavily in testing. Source

What people are saying

JVM bytecode is obviously not what I was talking about - it is neither low-level (if you can't efficiently compile the entirety of C into it, it's not good enough for this…

int_19h used a recommendation phrase. 8 indexed comments match. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 3:56:07 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year293 dated mentions

Observed mentions: 2020-06-20 21:16:58 UTC to 2026-10-11 05:47:52 UTC.

02040602020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 26 mentions; 1 submissions, 25 comments20202021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 69 mentions; 4 submissions, 65 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 69 mentions; 5 submissions, 64 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 35 mentions; 1 submissions, 34 comments20232024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 55 mentions; 9 submissions, 46 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 22 mentions; 3 submissions, 19 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 17 mentions; 1 submissions, 16 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC26125
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC69465
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC69564
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC35134
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC55946
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC22319
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC17116

From the project README

An excerpt from the repository, fetched Nov 12, 2026.

Read the project’s introduction
Cosmopolitan Cosmopolitan Libc makes C/C++ a build-once 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 7.3 + NetBSD + BIOS with the best possible performance and the tiniest footprint imaginable. Background For an introduction to this project, please read the actually portable executable blog post and cosmopolitan libc website. We also have API documentation. Getting Started You can start by obtaining a release of our cosmocc compiler from https://cosmo.zip/pub/cosmocc/. mkdir -p cosmocc cd cosmocc wget https://cosmo.zip/pub/cosmocc/cosmocc.zip unzip cosmocc.zip Here's an example program we can write: // hello.c #include <stdio.h> int main() { printf("hello world\n"); } It can be compiled as follows: cosmocc -o hello hello.c ./hello The Cosmopolitan Libc runtime links some heavyweight troubleshooting features by default, which are very useful for developers and admins. Here's how you can log system calls: ./hello --strace Here's how you can get a much more verbose log of function calls: ./hello --ftrace You can use the Cosmopolitan's toolchain to build conventional open source projects which use autotools. This strategy normally works: export CC=x86_64-unknown-cosmo-cc export CXX=x86_64-unknown-cosmo-c++ ./configure --prefix=/opt/cosmos/x86_64 make -j make install Cosmopolitan Source Builds Cosmopolitan can be compiled from source on any of our supported platforms. The Makefile will download cosmocc automatically. It's recommended that you install a systemwide APE Loader. This command requires sudo access to copy the ape command to a system folder and register with binfmt_misc on Linux, for even more performance. ape/apeinstall.sh You can now build the mono repo with any modern version of GNU Make. To bootstrap your build, you can install Cosmopolitan Make from this site: https://cosmo.zip/pub/cosmos/bin/make E.g.: curl -LO https://cosmo.zip/pub/cosmos/bin/make ./make -j8 o//examples/hello After you've built the repo once, you can also use the make from your cosmocc at .cosmocc/current/bin/make. You might even prefer to alias make to $COSMO/.cosmocc/current/bin/make. Since the Cosmopolitan repository is very large, you might only want to build one particular thing. Here's an example of a target that can be compiled relatively quickly, which is a simple POSIX test that only depends on core LIBC packages. rm -rf o//libc o//test .cosmocc/current/bin/make o//test/posix/signal_test o//test/posix/signal_test Sometimes it's desirable to build a subset of targets, without having to list out each individual one. For example if you wanted to build and run all the unit tests in the TEST_POSIX package, you could say: .cosmocc/current/bin/make o//test/posix Cosmopolitan provides a variety of build modes. For example, if you want really tiny binaries (as small as 12kb in size) then you'd say: .cosmocc/current/bin/make m=tiny You can furthermore cut out the bloat of other operating systems, and have Cosmopolitan become much more similar to Musl Libc. .cosmocc/current/bin/make m=tinylinux For further details, see //build/config.mk. Debugging To print a log of system calls to stderr: cosmocc -o hello hello.c ./hello --strace To print a log of function calls to stderr: cosmocc -o hello hello.c ./hello --ftrace Both strace and ftrace use the unbreakable kprintf() facility, which is able to be sent to a file by setting an environment variable. export KPRINTF_LOG=log ./hello --strace GDB Here's the recommended ~/.gdbinit config: set host-charset UTF-8 set target-charset UTF-8 set target-wide-charset UTF-8 set osabi none set complaints 0 set confirm off set history save on set history filename ~/.gdb_history define asm layout asm layout reg end define src layout src layout reg end src You normally run the .dbg file under gdb. If you need to debug the `` file itself, then you can load the debug symbols independently as gdb foo -ex 'add-symbol-file foo.dbg 0x401000' Platform Notes Shells If you use zsh and have trouble running APE programs try sh -c ./prog or simply upgrade to zsh 5.9+ (since we patched it two years ago). The same is the case for Python subprocess, old versions of fish, etc. Linux Some Linux systems are configured to launch MZ executables under WINE. Other distros configure their stock installs so that APE programs will print "run-detectors: unable to find an interpreter". For example: jart@ubuntu:~$ wget https://cosmo.zip/pub/cosmos/bin/dash jart@ubuntu:~$ chmod +x dash jart@ubuntu:~$ ./dash run-detectors: unable to find an interpreter for ./dash You can fix that by registering APE with binfmt_misc: 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" You should be good now. APE will not only work, it'll launch executables 400µs faster now too. However if things still didn't work out, it's also possible to disable binfmt_misc as follows: sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/cli' # remove Ubuntu's MZ interpreter sudo sh -c 'echo -1 > /proc/sys/fs/binfmt_misc/status' # remove ALL binfmt_misc entries WSL It's normally unsafe to use APE in a WSL environment, because it tries to run MZ executables as WIN32 binaries within the WSL environment. In order to make it safe to use Cosmopolitan software on WSL, run this: sudo sh -c "echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop" Discord Chatroom The Cosmopolitan development team collaborates on the Redbean Discord server. You're welcome to join us! https://discord.gg/FwAVVu7eJ4 Support Vector Platform Min Version Circa AMD K8 2003 Intel Core 2006 Linux 2.6.18 2007 Windows 8 [1] 2012 Darwin (macOS) 2
Read the full README on GitHub

What Hacker News says

293 sources
There is also the APE/Cosmopolitan cross platform binaries, which includes a python. Yes, cross platform binaries. The binaries run "natively on Linux + Mac + Windows + FreeBSD + OpenBSD 7.3 + NetBSD + BIOS with the best possible performance and the tiniest footprint imaginable." * Python Source: https://github.com/jart/cosmopolitan/tree/master/third_party... * Python Binary: https://cosmo.zip/pub/cosmos/bin/python which is ~ 40MB. Apparently you can zip your .py files in with the python binary and make it run, but I haven't had a chance to try and play with that yet.
In Self-contained highly-portable Python distributions
FWIW, that's existed for a while. Source at https://github.com/jart/cosmopolitan/tree/master/third_party... with downloadable binary at https://cosmo.zip/pub/cosmos/bin/sqlite3 . % curl -LO 'https://cosmo.zip/pub/cosmos/bin/sqlite3' % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 4845k 100 4845k 0 0 1384k 0 0:00:03 0:00:03 --:--:-- 1384k % chmod +x sqlite3 % file sqlite3 sqlite3: DOS/MBR boot sector; partition 1 : ID=0x7f, active, start-CHS (0x0,0,1), end-CHS (0x3ff,255,63), startsector 0, 4294967295 sectors % ./sqlite3 SQLite version 3.40.0 2022-11-16 12:10:08 Enter ".help" for usage hints. Connected to a transient in-memory database. Use ".open FILENAME" to reopen on a persistent databas
Read the rest
e. sqlite>:
In SQLite should have (Rust-style) editions
> I remember seeing a linux firewall/gateway set up to run with just the kernel, without any userspace at all. Completely unhackable. Do you remember any details that would let me search for it? Because that does sound cool, and even maybe useful; the thought has certainly crossed my mind that a router or VPN box doesn't really get a lot of use out of userspace... Although maybe it's worth keeping for control/configuration/debugging. > To print some text or run a simple program, I belive DOS without a memory manager would be even faster. Or just make your code boot directly. It's not hard to make a .efi, or use https://github.com/jart/cosmopolitan to make a binary that runs in many places including bare metal.
In Boot Naked Linux
Cool project! I know it's written in go, but it would be cool to see something like this which uses Cosmopolitan Libc + redbean or something similar to create a binary which runs anywhere. Would be fun to be able to pass around self-executable website archives. https://github.com/jart/cosmopolitan https://justine.lol/cosmopolitan/index.html https://redbean.dev (Certificates just expired for justine's website, just ignore the warning.)
In Show HN: Kage – Shadow any website to a single binary for offline viewing
The power move would have been Cosmopolitan, or a package similar to it. https://github.com/jart/cosmopolitan Cosmopolitan can be used to bundle up any gui package, and your code, and a team of professional software devs should be able to cope with it just fine. You end up with a native executable with a slightly bigger package to ship, since it's carrying executables for various platforms, but you'd effectively have the same code and behavior everywhere. A few extra megabytes, instead of whatever the hell electron is doing. They could also use Java, or even one of the electron type clones that attempt to be better, like Tauri. The point isn't that electron is so awful. It's that the company with the purportedly best coding AI and one of the best overall AI models in the world chose to do the absolute tawdriest, cheapest, even laziest thi
Read the rest
ng without any consideration of what the right thing to do might be, or what thing they could do that demonstrated their excellence and mastery of craft, or at a bare minimum, the advanced capabilities of the AI. Cursor used claude to build a browser from scratch; it's not like their AI couldn't do it.
In Claude is an Electron App because we've lost native
So what we need is essentially a "libc virtualization". But Musl is only available on Linux, isn't it? Cosmopolitan (https://github.com/jart/cosmopolitan) goes further and is available also on Mac and Windows, and it uses e.g. SIMD and other performance related improvements. Unfortunately, one has to cut through the marketing "magic" to find the main engineering value; stripping away the "polyglot" shell-script hacks and the "Actually Portable Executable" container (which are undoubtedly innovative), the core benefit proposition of Cosmopolitan is indeed a platform-agnostic, statically-linked C standard (plus some Posix) library that performs runtime system call translation, so to say "the Musl we have been waiting for".
In The Holy Grail of Linux Binary Compatibility: Musl and Dlopen

Showing the 15 most recent of 293 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.