Search code examples
crystal-lang

I can't build static binary of crystal program under alpine edge


I'm trying to compile simplest crystal program, but with --static flag:

The code:

# x.cr
puts "test"

Compilation:

crystal build --static x.cr

The result:

/usr/lib/gcc/x86_64-alpine-linux-musl/8.3.0/../../../../x86_64-alpine-linux-musl/bin/ld: cannot find -lgc (this usually means you need to install the development package for libgc)
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc "${@}" -o '/app/x'  -rdynamic -static  /usr/lib/libpcre.a -lgc /usr/lib/libpthread.a /usr/lib/crystal/core/ext/libcrystal.a /usr/lib/libevent.a /usr/lib/librt.a -L/usr/lib -L/usr/local/lib`

I'm guessing I'm missing some apk package. I tried gc, gc-dev, musl-dev - no luck - Is it package related, or am I missing something?


Solution

  • The answer seems to be that gc-dev doesn't provide a static library on edge any more. This used to be the case and still is in releases up to 3.9.

    There is a PR to fix that: https://github.com/alpinelinux/aports/pull/6970