The Crystal Programming Language Forum

Errors running v0.33.0, dyld: Library not loaded: /opt/crystal…

Hi there,

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.

Regards,
iain

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?

1 Like

Hi,

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).

Regards,
iain

The compiler uses pkg-config not pkgconf.

And it will run the following command to get the linker flags

$ pkg-config yaml --libs

Maybe you need to

$ ln -sf pkgconf /usr/bin/pkg-config

?

Hi bcardiff,

I’ve got pkg-config too, I’m just lazy with typing so favour pkgconf slightly, sorry :slight_smile:

For some unknown reason the .pc file was yaml-0.1.pc even though the version is 0.2.2. I don’t understand that naming convention.

Anyway, I’ve symlinked it to yaml.pc, now I get:

$ cat /opt/pkg/lib/pkgconfig/yaml.pc
prefix=/opt/pkg
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib

Name: LibYAML
Description: Library to parse and emit YAML
Version: 0.2.2
Cflags: -I${includedir}
Libs: -L${libdir} -lyaml


$ pkg-config yaml --libs
-L/opt/pkg/lib -lyaml 


$ l /opt/pkg/lib | ag yaml
-rw-r--r--    1 root  9.5M Feb 14 11:25 libLLVMObjectYAML.a
-rwxr-xr-x    1 root  212K Jan 28 03:03 libyaml-0.2.dylib
-rw-r--r--    1 root  239K Jan 28 03:03 libyaml.a
lrwxr-xr-x    1 root    17 Jan 28 03:03 libyaml.dylib -> libyaml-0.2.dylib
-rwxr-xr-x    1 root   950 Jan 28 03:03 libyaml.la

Should I perhaps symlink these as yaml.xx etc?

$ shards 
dyld: Library not loaded: /opt/crystal/embedded/lib/libyaml-0.2.dylib
  Referenced from: /Users/iainb/Library/Frameworks/Crystal.framework/Versions/Current/embedded/bin/shards
  Reason: image not found
[1]    17054 abort      shards

Crystal itself seems fine though, it’s just stuff in the embedded dir that fails. For instance, I tried it out on a simple program:

$ crystal run 02-Counting-the-number-of-characters.cr 
What is the input string?
testing
testing has 7 characters

If anything comes to mind, just let me know, and thanks for taking time on this, much appreciated.

Regards,
iain

Crystal itself seems fine though

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?

Regards,
iain

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)

See if it works. :see_no_evil:

That might work also :see_no_evil:

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.

It is now fixed! :partying_face: :partying_face:

My otool is broken for whatever reason so that was disappointing :grimacing: 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 :pray: and the insights. I really like the look of Crystal, can’t wait to try out a few more things.

No doubt I’ll be back asking for help soon!

Regards,
iain