When I install Crystal via apt-get on Ubuntu, it does not install everything it needs.
Dockerfile that reproduces the issue
test.cr is built into a binarytest outputs "WORKING!"I get the following error:
Error: execution of command failed with code: 127: `cc -o "/test" "${@}" -rdynamic -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
The command '/bin/sh -c crystal build -o test /tmp/test.cr' returned a non-zero code: 127
Do I still need to follow the "All required libraries" instructions? If so, wouldn't it be better for the package to specify them as deps? If that's not the issue, what's broken?
The wiki has a page for all required libs to install Crystal.
https://github.com/crystal-lang/crystal/wiki/All-required-libraries
@samueleaton thanks for the (very!) prompt reply :) I'm about to try that now. If that's what's required, it'd be much better for the package to specify its dependencies, as that was a nasty surprise.
@anicholson did everything work out for you? 馃檪
You need the packages in "All required libraries" for compiling Crystal itself, but Crystal won't compile a single program without having clang, ld and binutils installed - so I agree the crystal package must depend on those ones.
I've tested this on a Bash on Ubuntu on Windows installation - experimental, but you need those packages on any Ubuntu anyways.
@samueleaton my experience is pretty much exactly as @matiasgarciaisaia describes - the crystal package really needs to depend on those.
This seems to be a crystal-lang/omnibus-crystal issue, though, rather than a Crystal one.
You need the packages in "All required libraries" for compiling Crystal itself, but Crystal won't compile a single program without having clang, ld and binutils installed - so I agree the crystal package must depend on those ones.
Crystal, as other compiled languages based on LLVM will require you have some dependencies to allow linking the generated object files and produce executables.
Making crystal package to depend on build-essential seems a little bit too much, specially since we it doesn't care what is cc (could be clang, could be gcc).
I'm wondering how that is solved in Rust or Nim (if I麓m not mistaken they don't provide a apt compatible package).
@luislavena well could we at least mark them as recommended/suggested packages? The crystal package is broken without them, and makes for a really bad experience for new developers.
A Debian package can express alternative dependencies. Something like
"Depends: one-package; this-one|another-one;" tells apt that you need
one-package and either this-one or another-one. We could check which
packages provide a compatible cc and list them.
I don't know about rpm or other package managers, though.
Source: https://www.debian.org/doc/debian-policy/ch-relationships.html
The install instructions page (https://crystal-lang.org/docs/installation/on_debian_and_ubuntu.html) could at least list the dependencies "expected" as it is, you install the crystal package then you get
# crystal use_it_ssl.cr
--: 1: --: cc: not found
Error: execution of command failed with code: 127: `cc -o "/root/.cache/crystal/root-use_it_ssl.cr/macro-run-_opt_crystal_src_ecr_process.cr" "${@}" -rdynamic -lpcre -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
$ apt install gcc
# crystal use_it_ssl.cr
/usr/bin/ld: cannot find -lz
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
Error: execution of command failed with code: 1: `cc -o "/root/.cache/crystal/crystal-run-use_it_ssl.tmp" "${@}" -rdynamic -lz `command -v pkg-config > /dev/null && pkg-config --libs libssl || printf %s '-lssl -lcrypto'` `command -v pkg-config > /dev/null && pkg-config --libs libcrypto || printf %s '-lcrypto'` -lpcre -lm -lgc -lpthread /opt/crystal/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib`
That's just to compile a crystal file, not compile crystal itself, FWIW...
We've got a (sort of) umbrella issue here: https://github.com/crystal-lang/omnibus-crystal/issues/14
The "all required libraries" wiki page is only for hacking on Crystal itself. These libraries aren't required to use the Crystal compiler; the libraries required by the runtime are already shipped with the deb package (libgc, libevent, libpcre) along with libyaml.
In addition, there are a limited list of optional libraries that aren't required per-se; they could be listed as Recommended maybe: libxml2, libssl, and libcrypto; maybe libgmp too.
I.e. compiling a hello world program, or a program that doesn't need big numbers, SSL or XML should compile and run, right after installing the deb package. Otherwise there is an issue that should be tracked.
A potential issue, for example, is missing a C compiler, which Crystal requires to link the program. Maybe this could be solved by depending on the virtual c-compiler deb package.
@ysbaddaden IIRC the C compiler is only required for linking. Couldn't Crystal just depend on binutils (for ld), libgcc-4.8-dev, and libc6-dev, and just link it all together manually?
It probably could, yes. I'm not sure how ld works, and if calls would be portable or across platforms?
@ysbaddaden It is, though the exact command line is architecture-dependent (it should be reasonably simple to devise this from the actual arch, but I'm too lazy to look it up ATM). AFAIK it should look like:
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o -lc -lgcc -lgcc_s <object-files-go-here> /usr/lib/x86_64-linux-gnu/crtn.o
@rdp Hello ! I had some problemes with missing librairies too (-lz, -lssl, etc...) on Windows 10 with the server package. Today, for testing the shardes command I install git on the bash (the same I installed crystal). The librairies I install before I install git solves all my problemes. It's Magic !!!
apt-get install libcurl4-gnutls-dev libexpat1-dev gettext \
libz-dev libssl-dev
P.S. : Sorry, my english as bad as my programming skills :)
Most helpful comment
@samueleaton thanks for the (very!) prompt reply :) I'm about to try that now. If that's what's required, it'd be much better for the package to specify its dependencies, as that was a nasty surprise.