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 9–Nov 16 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/16/2026, 7:27:27 AM 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

69 sources
I used to do a lot of work on Bazel. I wrote its downloader code for example. https://github.com/bazelbuild/bazel/commit/ed7ced0018dc5c5eb... Bazel is nice, but these days I'm running a small scrappy operation, so I just use GNU Make. https://github.com/jart/cosmopolitan/blob/7064d736e3ded15087... I like Make since it's able to build a repository with 17k .o files, 80 .a archives, and 661 .com executables from scratch in under a minute on one personal computer (if the kernel page cache is warm). I wrote a couple small helper commands to make the make config more manageable, like package.com, mkdeps.com, compile.com, ar.com, zipobj.com, and runit.com. The reason why Make works for me, is because I think the root cause of needing things like Autoconf and Cmake is because most projects need to depend on seven different C libraries. I decided
Read the rest
that, rather than focusing on writing a better build config, I'd rather use an unfancy build system and instead devote my energy towards having a single C library that runs on all seven of the platforms I'm targeting. I owe a lot of thanks to projects like musl, dlmalloc, dtoa, llvm, etc. from whom I borrowed source code. That enabled me to abstract portability at the libc level, rather than punting to #ifdefs and configs.
In Show HN: Lisp with GC in 436 Bytes
These seem to be a way to embed all files to one executeable binary. Similar for Windows is https://github.com/sudachen/Molebox Others: - C/C++ has linker to link all to one binary - CLI/webserver only https://github.com/jart/cosmopolitan like https://redbean.dev . Same exe works on many x64 OS like Windows/macOS/Linux/BSD, it embeds .zip file and can read/write to embedded .zip on the fly. - AppImage https://appimage.org - Tclkit https://wiki.tcl-lang.org/page/Tclkit , creator at http://kitcreator.rkeene.org/kitcreator - Python Pop https://gitlab.com/saltstack/pop/pop - Go has some code also to embed all to one binary, some is part of Buffalo web framework https://gobuffalo.io/en -Godot Game engine https://godotengine.org can embed all to one executeable binary Is there anything else similar, that embeds all to one executeable binary?
In Enigma Virtual Box – Application Virtualization System for Windows
redbean has a https://redbean.dev/#LaunchBrowser function that lets you utilize the highest quality cross-platform gui that's already installed on the user's local machine. Think of it like Electron except with a 1mb install size rather than 100mb. I'm the author and I can tell you cosmo and redbean are ready to meet the needs of many use cases, and if they aren't then I want to know about it. We're also working to expand into OpenGL UX too. You can see our latest progress at https://github.com/jacereda/cosmogfx and the screenshots are here https://github.com/jart/cosmopolitan/issues/35#issuecomment-... which we're working hard to polish and get merged into the mainline. If you read threads like https://github.com/jart/cosmopolitan/issues/309 you can see we're committed to making sure your gui apps just work even on traditionally underser
Read the rest
ved platforms like OpenBSD because our goal is to help you reach the broadest audience possible. Please consider supporting the project!
In Why is Excalidraw so good?
Awesome website! I once knew a guy who was part of the Blocktronics crew who drew ANSI art painstakingly by hand cell by cell. The amount of effort that goes into these things is something else. There's obviously no algorithm that can produce a finished artwork as beautiful as a human can who sits down and uses a paint prog like this. But... If you want a scriptable tool for the command line that turns the image files you made with photoshop into something that's copy/pastable with UNICODE block characters, then here's an Actually Portable Executable that'll let you do just that. Screenshot: https://justine.lol/printansi.png Program: https://justine.lol/printansi.com Source code: https://github.com/jart/cosmopolitan/blob/master/tool/viz/pr...
In ASCII Paint
Karmic Koala is within the support vector of Actually Portable Executable. Since if you can get it to run on that, it'll most likely run on all the other distros too. Plus these binaries run on Windows 7, Mac, and BSDs too. They even run without an operating system. No need for recompilation. No virtual machine required. They aren't bloated either since the binary footprint starts at 12kb. See https://justine.lol/ape.html and https://github.com/jart/cosmopolitan Best part is you can still use the compiler that comes with your Linux. All it does is reconfigures the compiler so that, rather than producing a binary that can only run on one version of one distro of one operating system, your program magically becomes capable of running on all of them.
In Never update anything
> What I'm advocating for here requires that your program be compiled into a native executable binary file, and it must embed all its library dependencies (aka static linking). the super example of this is justine's project https://github.com/jart/cosmopolitan it's pr fucking cool > Cosmopolitan Libc makes 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 + NetBSD + BIOS with the best possible performance and the tiniest footprint imaginable.
In Designing Low Upkeep Software
Check out Cosmopolitan which vendors all its dependencies. https://github.com/jart/cosmopolitan You can't use Node with it, yet, but you can use QuickJS if you `make o//third_party/quickjs/qjs.com` and `o/third_party/quickjs/qjs.com -m third_party/quickjs/repl.js`. Cosmopolitan goes so far with vendoring dependencies that it actually has its own C library implementation that prevents functions like socket(), connect(), and getaddrinfo() from talking to the Internet if the software is running under GNU Make. Since sometimes we've found when porting software it'll have unit tests that do sneak leaks to public servers. It goes without saying that in order to make it even possible to vendor all dependencies, down to the binary level, there's a very long list of topologically ordered things that need to happen before you can even talk to the I
Read the rest
nternet. https://github.com/jart/cosmopolitan/blob/50937be7524197f23a... It's all cross platform and native at the same time for CLI/TUI. It'd surely make a more trustworthy tooling stack for a password manager than something like Electron since the temptation for people to incorporate things like FullStory into such GUIs is too great.
In The Persistent Gravity of Cross Platform
jart·Aug 26, 2021Recommendation phrase
This is one of the reasons why I've been building Cosmopolitan Libc. https://github.com/jart/cosmopolitan Alpine and Musl aren't radical enough on the bloat-free angle (since they don't fix root problem which is dynamic shared objects) and their definition of portability is supporting architectures like sega saturn but do nothing to support intel/amd microarchitectural dispatching, which is likely why you encountered performance issues. It's like, I love Musl so much, but I just didn't see the value in being able to port my apps to Sega Saturn if my C Library only runs on Linux and has suboptimal performance on x86. [side note] I seem to recall there being something about the the way the musl header files are written that basically throws a wrench into any scientific computing code that's compiled with it. Might have something to do with
Read the rest
security like those checks intended to prevent people from overlapping memcpy so someone should totally fix that.
In There is no such thing as a “glibc based alpine image”
The fact that the IMF thinks your choice of operating system should impact your creditworthiness is something I've been warning people about for months because it shows why we need cosmopolitan software. Since it's nice to have the ability to pick up and move our apps elsewhere should we discover we're using the "wrong" one. Because political winds change, but good engineering endures. https://github.com/jart/cosmopolitan
In IMF working paper suggests using browsing history in credit score calculations
I'm the author of the fastest open source HTTP server. Parsing HTTP 0.9, 1.0, and 1.1 is trivial. It's a walk in the park. It only takes about a hundred lines of code to create a proper O(n) parser. https://github.com/jart/cosmopolitan/blob/0b317523a0875d83d6... The Joyent HTTP parser used by Node is very good but it's implemented in a way that makes the problem much more complicated than it needs to be. The biggest obstacle with high-performance HTTP message parsing is the case-insensitive string comparison of header field names. Some servers like thttpd do the naive thing and just use a long sequence of strcasecmp() statements. Joyent goes "fast" because it uses callbacks, which effectively punts the problem to the caller, and, for a few select headers which it handles itself, like Content-Length, it uses this really complicated interna
Read the rest
l "h_matching" thing for doing painstakingly written out hardcoded character compares. Redbean solves the problem by using better computer science: perfect hash tables. Thanks to gperf command. That makes the API itself much more elegant since the parser can not only go faster but return a hash-table like structure where individual headers can be indexed without performing string comparisons.
In Show HN: Micro HTTP server in 22 lines of C
I don't think so. Compilers have gotten smart, but so have people. See for example stuff like this[0]. Hot path stuff still sees hand-written assembly even in this day and age because even modern compilers aren't able to provide enough overhead elision guarantees required for the really hardcore optimizations. What really happened is that thanks to the advances in computing power over the decades, we can now afford to skimp on performance most of the time - putting effort in optimizing only the most critical code paths - and still be able to get away with it. But when we're talking about squeezing every drop of performance, one of the big challenges with fighting against the JIT engine is figuring out when things deoptimize. This is because there are patterns (e.g. polymorphic code paths) that are inherently impossible to optimize perfect
Read the rest
ly (because halting problem). As soon as the runtime runs into a "weird" data type, deoptimization is forced to kick in and that can destroy performance. As a developer you have to be extremely mindful of this. Type systems like Typescript help, but you can still be effectively polymorphic (e.g. large union types, `any`, etc) if you're not being mindful of the underlying machine code. And JIT has one major downside that these benchmarks often intentionally omit in the name of "reducing noise": they usually take a while to warm up to native-like speed. I'm talking in the order of thousands of iterations running at a couple of order of magnitudes slower before JIT speeds fully kicks in. [0] https://github.com/jart/cosmopolitan/blob/master/libc/nexgen...
In Maybe you don't need Rust and WASM to speed up your JS (2018)

Showing the 15 most recent of 69 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.