Static linking libgc in crystal programs

Hi,

I created a Archlinux package for lavinmq, however @carlhoerberg told me that for peformance reasons libgc must be compiled with --enable-large-config, so static linked to not clash with system libgc that wasn’t compiled with this option.

Lavinmq devs when building lavinmq docker image they just put libgc.a into /usr/lib/crystal and it works, I tried here and in fact it works, however package creation is done in a sandbox and I can’t copy things outside it. So I tried linking flags, environment variables, both things and nothing worked :-/.

e.g:

$ CRYSTAL_LIBRARY_PATH=./src/gc-8.2.8/.libs crystal build hello.cr --link-flags="-Wl,-Bstatic -lgc"

Got

Error: execution of command failed with exit status 1: cc "${@}" -o /home/hugo/src/pet/aur/lavinmq/hello -Wl,-Bstatic -lgc -rdynamic -L./src/gc-8.2.8/.libs -lgc -lpthread -ldl -lpthread -lpthread -ldl

maybe the later -lgc crystal puts later ruined it, maybe I was just doign everything wrong… My guess is that CRYSTAL_LIBRARY_PATH environment variable was meant to be used on other libraries, not libraries that the crystal runtime depends on.

Now I’m writing this I had an idea that may work… :thinking: what it I tell crystal compiler to “cross compile” to the same architecture (so the quotes)? Because I remember that when passing the cross compilation flags it just create the object files and let the link to be done by the brave man doing cross compilation, so I could link the way I want… anyway, not yet tested, if anyone has a better idea I would be happy.

Thanks in advance.