I used the tar.gz method of installation onto a Mac 10.14 and the bin/crystal binary seems to work fine (not that I’ve done more than a Hello, World with it) but other things bring up errors. For example:
$ shards
dyld: Library not loaded: /opt/crystal/embedded/lib/libyaml-0.2.dylib
but crystal itself is fine:
$ crystal --version
Crystal 0.33.0 (2020-02-14)
LLVM: 6.0.1
Default target: x86_64-apple-macosx
Maybe I should unpack the tarball to /opt/crystal?
Any help or pointers much appreciated, and just let me know if this is more appropriate for the issue tracker.
The tar.gz archive for MacOS doesn’t include all required libraries. You need to install libyaml manually. I’m not using MacOS so I can’t give you any advice on how to do that.
However, the recommended way to install crystal (and shards) on MacOS is using brew. That makes sure all dependencies are installed as well.
This should be mentioned in the installation instructions. It only affects MacOS. On Linux, all libraries are statically linked.
Or maybe we could link libyaml statically on MacOS, too?
I can’t get Homebrew to install Crystal because it complains about my XCode tools, which aren’t working right now and won’t be until an upgrade so I chose the tar gz route.
I’ve got libyaml installed, but via pkgin so it’s not a standard location, though it does have a pkg-config entry.
$ pkgin search libyaml
libyaml-0.2.2nb1 = YAML 1.1 parser and emitter written in C
=: package is installed and up-to-date
$ pkgconf --variable=prefix yaml-0.1
/opt/pkg
$ pkgconf --libs yaml-0.1
-L/opt/pkg/lib -lyaml
I don’t know enough about dynamic linking to know why it’s not being picked up, though if you’ve ideas I’m willing to try them out.
It’s not urgent though, the Docker image works really well, but it would no doubt be helpful (not just to me).
I should clarify that. bin/crystal seems fine, embedded/bin/crystal (which I only found just now) doesn’t work, along with all the other things in embedded/bin, so:
$ embedded/bin/crystal run 02-Counting-the-number-of-characters.cr
Showing last frame. Use --error-trace for full trace.
In 02-Counting-the-number-of-characters.cr:1:1
1 | puts "What is the input string?"
^
Error: can't find file 'prelude'
If you're trying to require a shard:
- Did you remember to run `shards install`?
- Did you make sure you're running the compiler in the same directory as your shard.yml?
My previous comment will fix programs that you want to build. (like the compiler, that is way ./bin/crystal in your working directory works)
Can you try the following? go to the folder crystal-0.33.0-1 where you extracted the tar.gz
# verify the shards binary has an absolute reference to libyaml-0.2
$ otool -L embedded/bin/shards
embedded/bin/shards:
/opt/crystal/embedded/lib/libyaml-0.2.dylib (compatibility version 3.0.0, current version 3.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
# change the dylib reference
$ install_name_tool -change /opt/crystal/embedded/lib/libyaml-0.2.dylib @executable_path/../lib/libyaml-0.2.dylib embedded/bin/shards
$ otool -L embedded/bin/shards
embedded/bin/shards:
@executable_path/../lib/libyaml-0.2.dylib (compatibility version 3.0.0, current version 3.4.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1281.0.0)
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
bin/crystal sets up CRYSTAL_PATH to point to the location of the stdlib source (src folder). When calling embedded/bin/crystal, you need to manually configure the environment as the wrapper would do. So generally you’re not supposed to call that directly.
My otool is broken for whatever reason so that was disappointing but! untarring into /opt/crystal and putting bin and embedded/bin in the PATH means that calling shards now complains about Missing shard.yml. Please run 'shards init'.
Thanks to both @straight-shoota and @bcardiff, I’m sincerely very grateful for the support and the insights. I really like the look of Crystal, can’t wait to try out a few more things.