gcc is actually portable
Pre-release
Pre-release
gcc-11.2.0 can be built with Cosmopolitan Libc and the musl-cross-make
build system. This means you can build Actually Portable Executables using Actually Portable Executables! Here's what you need to do:
- download the Cosmopolitan Libc amalgamation from https://justine.lol/cosmopolitan/cosmopolitan.zip
- download
gcc11.zip
from here, and ensure the binaries within are available on$PATH
(or%PATH%
if you're on Windows) - build the sample executable as given in the Cosmopolitan Libc README:
printf 'main() { printf("hello world\\n"); }\n' >hello.c
gcc.com -g -Os -static -nostdlib -nostdinc -fno-pie -no-pie -mno-red-zone \
-fno-omit-frame-pointer -pg -mnop-mcount -mno-tls-direct-seg-refs -gdwarf-4 \
-o hello.com.dbg hello.c -fuse-ld=bfd -Wl,-T,ape.lds -Wl,--gc-sections \
-Wl,-z,common-page-size=0x1000 -Wl,-z,max-page-size=0x1000 \
-include cosmopolitan.h crt.o ape-no-modify-self.o cosmopolitan.a
objcopy.com -S -O binary hello.com.dbg hello.com
tested on Linux (Debian 11/Fedora 35) and Windows, see attached screenshot: