Cross-compiling -- needs libcrystal.a


#1

I’m trying to cross-compile an application to ARMv6 (original raspberry pi). If I run the command output by crystal build on the Pi, I get the following error:

cc: error: /usr/share/crystal/src/ext/libcrystal.a: No such file or directory

How do I get a libcrystal.a for a target platform which doesn’t have a compiled Crystal?


#2

I think cross compiling is currently broken because of that libcrystal.a. That library currently results from compiling this file. Ideally we could write that file in Crystal and there wouldn’t be a need for a libcrystal.a.

I’m not sure Crystal will work on a raspberry pi.


#3

Well, I definitely don’t think the Pi itself would be able to compile crystal, but I don’t see any reason cross-compiled binaries wouldn’t work. Thanks for the helpful links, I’ll look into it some more in a bit.


#4

Well… I got all the linked binaries installed, compiled sigfault.c as libcrystal.a, and ran the command…which gave me this error:

flix.arm.o: In function `__crystal_main':
/usr/share/crystal/src/kernel.cr:543: undefined reference to `setup_sigfault_handler'
flix.arm.o: In function `crypto_scrypt':
/home/scott/Documents/code/flix/lib/scrypt/src/engine.cr:38: undefined reference to `crypto_scrypt'
collect2: error: ld returned 1 exit status

the command was

cc 'flix.arm.o' -o 'flix.arm'  -rdynamic  -L/home/scott/Documents/code/flix/lib/scrypt/src/../ext -lscrypt -lz `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto'` -lyaml -lmagic -lpcre -lm -lgc -lpthread /usr/share/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib

I’m just documenting what happened, I’ll do some more research on this a little while later. :/


#5

For completeness, on the cross-compiling target platform, you need to check out the Crystal repo and run make libcrystal in order to build libcrystal.a.
(Actually, you don’t need the entire repo, Makefile and src/ext folder should be enough).


#6

thanks!