Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS Could not open library 'libglib-2.0.dylib': dlopen(libglib-2.0.dylib, 5): image not found #130

Closed
stereobooster opened this issue Sep 4, 2017 · 15 comments
Labels

Comments

@stereobooster
Copy link

/opt/boxen/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ffi-1.9.18/lib/ffi/library.rb:147:in `block in ffi_lib': Could not open library 'glib-2.0': dlopen(glib-2.0, 5): image not found. (LoadError)
Could not open library 'libglib-2.0.dylib': dlopen(libglib-2.0.dylib, 5): image not found
	from /opt/boxen/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ffi-1.9.18/lib/ffi/library.rb:100:in `map'
	from /opt/boxen/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ffi-1.9.18/lib/ffi/library.rb:100:in `ffi_lib'
	from /opt/boxen/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby-vips-2.0.6/lib/vips.rb:28:in `<module:GLib>'
	from /opt/boxen/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/ruby-vips-2.0.6/lib/vips.rb:13:in `<top (required)>'
	from ruby_io_speed.rb:1:in `require'
	from ruby_io_speed.rb:1:in `<main>'
rake aborted!
@jcupitt
Copy link
Member

jcupitt commented Sep 4, 2017

Hello, how did you install libvips? If you use brew, libglib-2.0.dylib should be on your system as well.

@stereobooster
Copy link
Author

brew install glib
Warning: glib 2.52.3 is already installed

Yes it is brew

@jcupitt
Copy link
Member

jcupitt commented Sep 5, 2017

I just tried on my mac and it all seems to work for me. Here's what I see. First, brew:

john@katamata ~ $ brew update
Already up-to-date.
john@katamata ~ $ brew install vips
==> Downloading https://homebrew.bintray.com/bottles/vips-8.5.8.sierra.bottle.ta
==> Downloading from https://akamai.bintray.com/6f/6f18a2e5a7cf90c137d809258e5ff
######################################################################## 100.0%
==> Pouring vips-8.5.8.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/vips/8.5.8: 189 files, 12.8MB
john@katamata ~ $ ls /usr/local/lib/libglib*
/usr/local/lib/libglib-2.0.0.dylib /usr/local/lib/libglib-2.0.dylib
/usr/local/lib/libglib-2.0.a
john@katamata ~ $ vips --version
vips-8.5.8-Tue Aug 29 10:02:35 BST 2017

Then Ruby (I'm using the old Apple one):

john@katamata ~ $ which gem
/usr/bin/gem
john@katamata ~ $ which ruby
/usr/bin/ruby
john@katamata ~ $ ruby --version
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin16]
john@katamata ~ $ gem install ruby-vips
Fetching: ffi-1.9.18.gem (100%)
Building native extensions.  This could take a while...
Successfully installed ffi-1.9.18
Fetching: ruby-vips-2.0.6.gem (100%)
Successfully installed ruby-vips-2.0.6
Parsing documentation for ffi-1.9.18
Installing ri documentation for ffi-1.9.18
Parsing documentation for ruby-vips-2.0.6
Installing ri documentation for ruby-vips-2.0.6
2 gems installed
john@katamata ~ $ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> x = Vips::Image.black 10, 10
=> #<Image 10x10 uchar, 1 bands, b-w>

So I'd check:

  • you have glib and libvips in /usr/local/lib
  • you can run command-line vips stuff correctly
  • your gem and Ruby know about /usr/local

@jcupitt
Copy link
Member

jcupitt commented Sep 5, 2017

I tried with the brew Ruby and that worked too.

$ ruby --version
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin16]

@stereobooster
Copy link
Author

ruby --version
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]
gem -v
2.5.1
gem install ruby-vips
Fetching: ruby-vips-2.0.6.gem (100%)
# it is not building it, why?
Successfully installed ruby-vips-2.0.6
1 gem installed

@jcupitt
Copy link
Member

jcupitt commented Sep 6, 2017

Hello again, it doesn't need to build it, it's all written in Ruby, it uses FFI to call into the dylib.

Were you able to confirm that you have the dylibs in /usr/local/lib and that the command-line vips works?

If they are fine, I think the issue must be with your Ruby install. For some reason it cannot see libraries in /usr/local/lib. You probably need to check your configuration.

@stereobooster
Copy link
Author

/opt/boxen/homebrew/Cellar/glib/2.52.3/lib/libglib-2.0.0.dylib
vips --version
vips-8.5.8-Mon Sep  4 21:14:48 CEST 2017

your gem and Ruby know about /usr/local

What does this mean?

@jcupitt
Copy link
Member

jcupitt commented Sep 7, 2017

Do you have the libraries in /usr/local/lib? I see:

john@katamata ~ $ ls /usr/local/lib/libglib*
/usr/local/lib/libglib-2.0.0.dylib /usr/local/lib/libglib-2.0.dylib
/usr/local/lib/libglib-2.0.a

@stereobooster
Copy link
Author

Nope, homebrew installed it in other place

brew --prefix glib
/opt/boxen/homebrew/opt/glib

@ioquatix
Copy link
Member

I'm not sure why this isn't working with Macports but after I manually (yuck) copied the required library to /usr/local/lib, it worked. So, is there something special about /usr/local/lib but not /opt/local/lib?

@thubamamba
Copy link

Facing this error on M1, any quick fix?

@thanadol-git
Copy link

Facing this error on M1, any quick fix?

Same for me

@jcupitt
Copy link
Member

jcupitt commented Aug 10, 2022

It's an ffi issue -- ruby-vips is asking for glib-2.0.0, and ffi is failing to locate the library.

Here's the ruby-vips code:

https://github.com/libvips/ruby-vips/blob/master/lib/vips.rb#L13-L45

This then runs here in ffi:

https://github.com/ffi/ffi/blob/master/lib/ffi/library.rb#L34-L112

As you can see, it'll first try dlopen("libglib-2.0.0.dylib"), which ought to be the name of the library on your platform. If you don't have your library path set up, dlopen() will fail and you'll drop into ffi's rather haphazard fallback system:

https://github.com/ffi/ffi/blob/master/lib/ffi/library.rb#L129

You can see it has various possible directories wired into the code. If you're lucky, one of these will happen to be correct and it'll work. Homebrew on apple silicon uses a directory that's NOT on that list, so it'll always fail.

I think the best solution is to get your system library lookup working. Try man dyld and have a look at the env vars you can set. I don't have an M1 mac, so I can't experiment myself, unfortunately.

If you look on ffi, you'll find several PRs which attempt to improve this unfortunate situation. ioquatix has tried, and there are others in the list as well:

ffi/ffi#968

ffi/ffi#963

@Merovex
Copy link

Merovex commented Aug 15, 2022

Looking at @jcupitt 's comments, I went to ffi/ffi#968 and to the forked library. From there, I went to gems/ffi-1.15.5/lib/ffi which is the culprit for me.

Yields a satisfying:

irb
3.1.2 :001 > require 'vips'
 => true 

Yes, this is a hack. But, it looks like there is conversation around a long-term fix, and this gets me through the night.

@jcupitt
Copy link
Member

jcupitt commented Aug 15, 2022

Oh nice @Merovex. If you have time, I'd post a patch to that ffi issue as an example of what's fixed it for you. It might help the devs there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants