Skip to content

Instantly share code, notes, and snippets.

@doublec
Last active August 12, 2018 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save doublec/672e40ca0a74c26c2e85f2722cdd8c9f to your computer and use it in GitHub Desktop.
Save doublec/672e40ca0a74c26c2e85f2722cdd8c9f to your computer and use it in GitHub Desktop.
Building SWI-Prolog statically with musl libc
# Build musl libc
$ git clone git://git.musl-libc.org/musl
$ cd musl
$ ./configure
$ make
$ sudo make install
$ export PATH=$PATH:/usr/local/musl/bin/
# build libz for musl
$ wget https://zlib.net/zlib-1.2.11.tar.gz
$ tar xvf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11/
$ CC=musl-gcc ./configure --prefix=/usr/local/musl -static
$ make
$ sudo make install
# Clone swipl source
# $ git clone https://github.com/SWI-Prolog/swipl-devel swipl-musl
$ git clone --branch musl_compatibility https://github.com/doublec/swipl-devel swipl-musl
$ cd swipl-musl
$ ./prepare
$ cp build.templ build
$ ...edit build and change...
PREFIX=/tmp/swipl-musl
export CC=musl-gcc
export COFLAGS="-O2 -fno-strict-aliasing -gdwarf-2 -g3 -static"
export LDFLAGS="-O2 -g -static"
EXTRACFG+=" --disable-shared"
$ ./build
# Test
$ export PATH=/tmp/swipl-musl/bin:$PATH
$ ldd /tmp/swipl-musl/bin/swipl
statically linked
$ cat >test.pl
main :-
write("Hello World!"), nl, halt.
$ swipl --goal=main --stand_alone=true -o test -c test.pl
$ ./test
Hello World!
$ ldd test
statically linked
$ ls -l test
-rwxr-xr-x 1 user user 8182708 Mar 15 13:16 test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment