build-once run-anywhere c library
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. For further details, read Cosmopolitan Third Edition, the Cosmo README, and the Cosmopolitan Toolchain README.
Our latest 3.2 release features exciting fixes and improvements.
We've fixed important threading bugs on /zip/...
file descriptors.
We now have a hack that lets you use cosmo binaries as a login shell. Setuid security is improved. Executable path self-detection is better. There's a new APE loader version as a result. If you have a systemwide APE loader install, it's recommended that you upgrade, but not required.
Our public header files now have better open source compatibility.
gid_t
and uid_t
in passwd.h
(#995)tcgetpgrp
and tcsetpgrp
decls to unistd.h
(#996) (#997)make
work right on aarch64(win32 error 0)
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.
This release fixes issues with the 3.0.x series. A new cosmo_dlopen()
function is now provided that's good enough to load nontrivial dynamic libraries on all platforms except OpenBSD. Cosmos binaries are now being distributed on our new online service https://cosmo.zip/ that's operated by the Cosmopolitan authors. This release was made possible thanks to the testing and contribution efforts of our GitHub and Discord communities https://discord.gg/FwAVVu7eJ4. Thank you!
cosmocc
toolchain#include <shared_mutex>
args
replace ...
only at the end of file (#909)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.
Some Linux systems are configured to launch MZ executables under WINE or run-detectors
. 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 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"
If things still aren't working, 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 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"
getifaddrs()
024be3b009d500970168e41f375ff8f0c79c80b0dlopen()
support 5e8c928f1a37349a8c72f0b6aae5e535eace3f41getcwd()
on Windows which was causing weirdness with bash
1eb6484c9c89b3cf85cd9f235aef70e1e5ed1776M-x package-list-packages
will work on Windows/usr/local/bin/ape
(instead of /usr/bin/ape
) on Apple Silicon for systemwide APE.longjmp()
safe d7917ea076df24967ec578c5dabe1ce30b93793d\n
in /zip/.args
files 585c86e2a439d5df23595b249eb28554764ec6b4cosmocc -dumpmachine
workIf you've used ape-install
or ape/ape-install.sh
in the past (to install the system-wide APE Loader) then you need to run it again so that your system can use APE Loader v1.9. This new release of APE Loader fixes bugs. Apple M1 systems need it to run the APE binaries in this release..It's also backwards compatible with all APE and static ELF binaries ever made with Cosmo. Any of your own programs which you've compiled before on Apple Silicon which use execve()
may need to be recompiled in order to run the latest APE executables unless you've installed a system-wide APE Loader.
It's recommended that cosmocc
users run:
cd /opt/cosmo
rm -rf o/third_party/gcc
unzip -vl cosmocc-0.0.18.zip
To get the latest build of Cosmopolitan's toolchain.
Release notes: https://justine.lol/cosmo3/
Release notes upcoming.
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 to output a POSIX-approved polyglot format that runs natively on Linux + Mac + Windows + FreeBSD + OpenBSD + NetBSD + BIOS or UEFI with the best possible performance and the tiniest footprint imaginable.
If you use Linux, then you can build Cosmopolitan and its included software from source as follows:
wget https://justine.lol/cosmopolitan/cosmopolitan-2.2.tar.gz
tar xf cosmopolitan-2.2.tar.gz
cd cosmopolitan
build/bootstrap/make.com -j8
o//examples/hello.com
If you're doing your development work on Linux or BSD and you want to bring your own build system, then you need just five files to get started:
wget https://justine.lol/cosmopolitan/cosmopolitan-amalgamation-2.2.zip
unzip cosmopolitan-amalgamation-2.2.zip
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone -gdwarf-4 \
-fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs \
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -Wl,--gc-sections \
-include cosmopolitan.h crt.o ape-no-modify-self.o cosmopolitan.a
objcopy -S -O binary hello.com.dbg hello.com