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

**URL:** <https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734>\
**Category:** Offtopic\
**Created:** [February 19, 2020, 6:35am UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734 "2020-02-19T06:35:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![yb66](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/yb66/32/739_2.png) [@yb66](https://forum.crystal-lang.org/u/yb66)\
**Post date:** [February 19, 2020, 6:35am UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/1 "2020-02-19T06:35:33Z")

</div>

Hi there,

I used the [tar.gz method of installation](https://crystal-lang.org/install/from_targz/) 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

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [February 19, 2020, 10:49am UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/2 "2020-02-19T10:49:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [February 19, 2020, 10:53am UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/3 "2020-02-19T10:53:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![yb66](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/yb66/32/739_2.png) [@yb66](https://forum.crystal-lang.org/u/yb66)\
**Post date:** [February 20, 2020, 5:27am UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/4 "2020-02-20T05:27:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [February 20, 2020, 12:11pm UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/5 "2020-02-20T12:11:16Z")

</div>

The compiler uses `pkg-config` not `pkgconf`.

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

```auto
$ pkg-config yaml --libs

```

Maybe you need to

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

```

?

---

<div class="post-metadata">

**Author:** ![yb66](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/yb66/32/739_2.png) [@yb66](https://forum.crystal-lang.org/u/yb66)\
**Post date:** [February 20, 2020, 1:54pm UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/6 "2020-02-20T13:54:41Z")

</div>

Hi bcardiff,

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

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

---

<div class="post-metadata">

**Author:** ![yb66](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/yb66/32/739_2.png) [@yb66](https://forum.crystal-lang.org/u/yb66)\
**Post date:** [February 20, 2020, 1:59pm UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/7 "2020-02-20T13:59:08Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [February 20, 2020, 2:32pm UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/8 "2020-02-20T14:32:11Z")

</div>

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

```bash
# 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. 🙈

> [@yb66](#):
>
> Maybe I should unpack the tarball to /opt/crystal?

That might work also 🙈

---

<div class="post-metadata">

**Author:** ![straight-shoota](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/straight-shoota/32/36_2.png) [@straight-shoota](https://forum.crystal-lang.org/u/straight-shoota)\
**Post date:** [February 20, 2020, 2:49pm UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/9 "2020-02-20T14:49:38Z")

</div>

> [@yb66](#):
>
> `embedded/bin/crystal` (which I only found just now) doesn’t work, along with all the other things in `embedded/bin`

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

---

<div class="post-metadata">

**Author:** ![yb66](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/yb66/32/739_2.png) [@yb66](https://forum.crystal-lang.org/u/yb66)\
**Post date:** [February 21, 2020, 7:56am UTC](https://forum.crystal-lang.org/t/errors-running-v0-33-0-dyld-library-not-loaded-opt-crystal/1734/10 "2020-02-21T07:56:21Z")

</div>

It is now fixed! 🥳 🥳

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.

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

Regards,  
iain
