libvips / ruby-vips

Ruby extension for the libvips image processing library.
MIT License
829 stars 61 forks source link

Little help? Could not open library 'glib-2.0.0': dlopen(glib-2.0.0, 5): image not found. #284

Closed bdhartz closed 3 years ago

bdhartz commented 3 years ago

Hi team (John? Anyone?) Hoping for some help. I've spent hours on github/stackoverflow trying to triage this issue. Admittedly, I'm new to ruby and very new to getting development environments set up. I am on an M1 mac.

My VIPs-related unit tests fail with the following error: LoadError: Could not open library 'glib-2.0.0': dlopen(glib-2.0.0, 5): image not found. Could not open library 'libglib-2.0.0.dylib': dlopen(libglib-2.0.0.dylib, 5): image not found

Would really appreciate any help here. Also would be happy to jump on a zoom call and report findings back here!

Notes from my investigation/previous issues: (1) https://github.com/libvips/ruby-vips/issues/130 - libglib-2.0.dylib is on my system, in a few different places actually. Is the code looking for it somewhere else?

$ locate libglib-2.0.dylib /opt/homebrew/Cellar/glib/2.66.7/lib/libglib-2.0.dylib /opt/homebrew/lib/libglib-2.0.dylib /usr/local/lib/libglib-2.0.dylib /usr/local/libglib-2.0.dylib

I see the suggestion that I should check: you have glib and libvips in /usr/local/lib - should they really be here if I'm primarily using brew, which puts things elsewhere? I've tried copying a bunch of files into /usr/local/lib, but I'm not sure exactly which files should be here for l you can run command-line vips stuff correctly - irb > require 'vips' fails with the error mentioned above. your gem and Ruby know about /usr/local - how can I check this?

(2) vips --version output: vips-8.10.5-Fri Dec 18 10:14:09 UTC 2020

(3) I saw some other suggestions (I can't find them now) to modify lib/ffi/library.rb to use a direct path. However, LIBC = '/usr/lib/libc.dylib' #original value

LIBC = '/System/DriverKit/usr/lib/system/libsystem_c.dylib' - tried this, didn't work

#LIBC = '/opt/homebrew/Cellar/tcl-tk/8.6.11_1/lib/tcllibc/macosx-arm-clang/tcllibc.dylib' - tried this, didn't work

Interestingly, the output of $ locate libc.dylib is below. /opt/homebrew/Cellar/tcl-tk/8.6.11_1/lib/tcllibc/macosx-arm-clang/tcllibc.dylib

Looking for any guidance or suggestions. Thank you so much! Apologies if this is posted incorrectly, happy to remove it elsewhere. Thank you!

jcupitt commented 3 years ago

Hi @bdhartz,

It used to "just work", but I've not tried ruby-vips on macos for a while, perhaps things have changed. I'll have a go later today.

bdhartz commented 3 years ago

Hi @bdhartz,

It used to "just work", but I've not tried ruby-vips on macos for a while, perhaps things have changed. I'll have a go later today.

Thanks John, I look forward to hearing back! Let me know if you'd like to hop on a call or if I can provide any further info.

jcupitt commented 3 years ago

Oh, an M1 mac, I just noticed. I think brew is still a bit wobbly on the M1, you might need to wait a few months more before it'll work smoothly.

On this old imac I see:

21:45 $ brew install vips
==> Downloading https://homebrew.bintray.com/bottles/vips-8.10.5_2.catalina.bott
Already downloaded: /Users/john/Library/Caches/Homebrew/downloads/f57d2661c5701c4dfd7dc1bd9c4b9d068a75e845caa9ed5c1abedce79f8f33a7--vips-8.10.5_2.catalina.bottle.tar.gz
==> Pouring vips-8.10.5_2.catalina.bottle.tar.gz
Warning: vips dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
🍺  /usr/local/Cellar/vips/8.10.5_2: 167 files, 13.9MB
✔ ~ 
21:46 $ ls -l /usr/local/lib/*vips*
lrwxr-xr-x  1 john  admin  48  8 Mar 21:46 /usr/local/lib/libvips-cpp.42.dylib -> ../Cellar/vips/8.10.5_2/lib/libvips-cpp.42.dylib
lrwxr-xr-x  1 john  admin  41  8 Mar 21:46 /usr/local/lib/libvips-cpp.a -> ../Cellar/vips/8.10.5_2/lib/libvips-cpp.a
lrwxr-xr-x  1 john  admin  45  8 Mar 21:46 /usr/local/lib/libvips-cpp.dylib -> ../Cellar/vips/8.10.5_2/lib/libvips-cpp.dylib
lrwxr-xr-x  1 john  admin  44  8 Mar 21:46 /usr/local/lib/libvips.42.dylib -> ../Cellar/vips/8.10.5_2/lib/libvips.42.dylib
lrwxr-xr-x  1 john  admin  37  8 Mar 21:46 /usr/local/lib/libvips.a -> ../Cellar/vips/8.10.5_2/lib/libvips.a
lrwxr-xr-x  1 john  admin  41  8 Mar 21:46 /usr/local/lib/libvips.dylib -> ../Cellar/vips/8.10.5_2/lib/libvips.dylib
✔ ~ 
21:49 $ gem install ruby-vips
Fetching ruby-vips-2.1.0.gem
Successfully installed ruby-vips-2.1.0
Parsing documentation for ruby-vips-2.1.0
Installing ri documentation for ruby-vips-2.1.0
Done installing documentation for ruby-vips after 0 seconds
1 gem installed
✔ ~ 
21:49 $ irb
irb(main):001:0' require 'vips'
=> true
irb(main):002:0> 
jonfer commented 3 years ago

I have the same problem, with an M1 as well. Let me know if you find a solution. Thank you

jcupitt commented 3 years ago

Sorry, I don't know what's wrong with your system. I did the most basic install and it all worked. Are you maybe attempting to use the Apple ruby? It blocks third party libraries for security. You must use the homebrew ruby.

On my mac (2012 imac), I see this:

10:49 $ which ruby
/usr/local/opt/ruby/bin/ruby
✔ ~ 
10:49 $ which vips
/usr/local/bin/vips
✔ ~ 

So I used brew to install vips and ruby and they are both in /usr/local.

10:50 $ 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
✔ ~ 
10:50 $ ls /usr/local/lib/libvips*
/usr/local/lib/libvips-cpp.42.dylib /usr/local/lib/libvips.42.dylib
/usr/local/lib/libvips-cpp.a        /usr/local/lib/libvips.a
/usr/local/lib/libvips-cpp.dylib    /usr/local/lib/libvips.dylib
✔ ~ 

The relevant libraries are in there too.

10:50 $ vips --help
Usage:
  vips [OPTION…] [ACTION] [OPTIONS] [PARAMETERS] - VIPS driver program
...

I can run the vips command-line stuff.

10:50 $ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> 

And I can gem install ruby-vips and require it.

bdhartz commented 3 years ago

I think @jonfer is having an issue on a mac with M1/silicon architecture, similar to me above. I don't believe there was a solution for now.

DotIN13 commented 3 years ago

Having the same problem using ruby-vips with Jekyll Picture Tag on an M1 Macbook.

jcupitt commented 3 years ago

Hi @DotIN13, you need to give a lot more information. What error did you get, how did you install everything, what versions are you running, where is your glib installed, which ruby are you using etc. etc.

Could it perhaps be a native vs. x86 problem? For example, if glib has been built for x86 and ruby is native it obviously won't work.

kleisauke commented 3 years ago

I think PR https://github.com/ffi/ffi/pull/882 might fix this. As a workaround, you could try to symlink the whole /opt/homebrew/lib directory to /opt/local/lib (untested).

DotIN13 commented 3 years ago

Error

Dependency Error: Yikes! It looks like you don't have jekyll_picture_tag or one of its dependencies installed. In order to use Jekyll as currently configured, you'll need to install this gem. If you've run Jekyll with bundle exec, ensure that you have included the jekyll_picture_tag gem in your Gemfile as well. The full error message from Ruby is: 'Could not open library 'glib-2.0.0': dlopen(glib-2.0.0, 5): image not found. Could not open library 'libglib-2.0.0.dylib': dlopen(libglib-2.0.0.dylib, 5): image not found' If you run into trouble, you can find helpful resources at https://jekyllrb.com/help/!

  Jekyll 4.2.0   Please append `--trace` to the `serve` command 
                 for any additional information or backtrace. 
                ------------------------------------------------

How did I install everything?

brew: official install script, arm64

glib, vips: via brew, arm64

ruby: via rbenv, arm64

Ruby Version

ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [arm64-darwin20]

glib

glib: stable 2.68.0 (bottled)
Core application library for C
https://developer.gnome.org/glib/
/opt/homebrew/Cellar/glib/2.68.0 (442 files, 22.0MB) *

vips info

vips: stable 8.10.6 (bottled)
Image processing library
https://github.com/libvips/libvips
/opt/homebrew/Cellar/vips/8.10.6 (167 files, 14.2MB) *

So I guess it's all native but something just went wrong.

DotIN13 commented 3 years ago

I think PR ffi/ffi#882 might fix this. As a workaround, you could try to symlink the whole /opt/homebrew/lib directory to /opt/local/lib (untested).

After symlinking with the following command, it worked like butter, thanks a lot.

sudo ln -s /opt/homebrew/lib /opt/local/lib

jcupitt commented 3 years ago

Ah thanks for that Kleis, I hadn't realized homebrew had moved the lib area.

Related: https://github.com/ioquatix/ffi-module

A more modern interface to ruby-ffi which has much better library searching. It might be useful to experiment with something similar.

rdetert commented 3 years ago

@DotIN13 @kleisauke Yes, this works. M1 strikes again!

bdhartz commented 3 years ago

@rdetert @DotIN13 @kleisauke - thanks for your work on this! For whatever reason, I don't have a /opt/local directory, so sudo ln -s /opt/homebrew/lib /opt/local/lib fails with ln: /opt/local/lib: No such file or directory. My /opt/ only has homebrew in it, nothing else. Should I have a /opt/local and is there a way you know of that I can get this back to how it should be? Thanks a bunch!

DotIN13 commented 3 years ago

@bdhartz You could try creating /opt/local with mkdir -p /opt/local/lib.

greycampbell commented 3 years ago

I think PR ffi/ffi#882 might fix this. As a workaround, you could try to symlink the whole /opt/homebrew/lib directory to /opt/local/lib (untested).

After symlinking with the following command, it worked like butter, thanks a lot.

sudo ln -s /opt/homebrew/lib /opt/local/lib

This was close for me, but I had to do sudo ln -s /opt/homebrew/lib /usr/local/lib to get it to work. I'd tried to install the older homebrew so this path already existed for me; you might have to manually create it

mmhan commented 3 years ago

I followed the instructions to create a symlink and I got the following error on my m1 machine.

❯ rails c
Running via Spring preloader in process 13791
Loading development environment (Rails 6.0.3.2)
2.6.5 :001 > require 'vips'
objc[13791]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[13791]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

I also get the same error if I used the ffi with ffi/ffi#882 fix implemented.

Is anyone else getting that?

greycampbell commented 3 years ago

I followed the instructions to create a symlink and I got the following error on my m1 machine.

❯ rails c
Running via Spring preloader in process 13791
Loading development environment (Rails 6.0.3.2)
2.6.5 :001 > require 'vips'
objc[13791]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[13791]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

I also get the same error if I used the ffi with ffi/ffi#882 fix implemented.

Is anyone else getting that?

@mmhan I might be wrong but try adding "export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" to your .bashrc or .zshrc

mmhan commented 3 years ago

@greycampbell - Yep, it worked! Thanks!

Adverbly commented 2 years ago

I ran into this as well. Also on M1. Had to modify the symlimk comments from above because I couldn't directly link the entire directory. What I used:

 sudo ln -s /opt/homebrew/lib/libglib-2.0.0.dylib /usr/local/lib/
 sudo ln -s /opt/homebrew/lib/libvips.42.dylib /usr/local/lib/
 sudo ln -s /opt/homebrew/lib/libgobject-2.0.0.dylib /usr/local/lib/
leandrocastro commented 2 years ago

I managed to solve it like this:

sudo ln -s /opt/homebrew/lib /opt/local/lib

Then I removed all installed gems:

yes Y | gem uninstall -a -I

Then I installed the bundle

gem install bundler

Then I installed all the gems again:

bundle install

donncha commented 2 years ago
$ bundle update ffi

might fix it. v1.15.0 doesn't look in /opt/homebrew/lib. v1.15.3+ does.

galohernandez commented 1 year ago

I did all the fixes but had no luck. Fixed using the command

brew install vips

Maybe this could help1

stevecondylios commented 1 year ago

@Adverbly's solution worked perfectly for me. I didn't quite understand what was going on, so I looked around a bit and learned:

file /opt/homebrew/lib/libglib-2.0.0.dylib
# /opt/homebrew/lib/libglib-2.0.0.dylib: Mach-O 64-bit dynamically linked shared library arm64

super handy!

Hope it's useful.

mattlindsey commented 1 year ago

I just had this issue on a new M2 mac and solved it by removing the old x86 homebrew:

curl -fsSL -o /tmp/uninstall.sh https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh
arch -x86_64 /bin/bash /tmp/uninstall.sh --path=/usr/local
jdsampayo commented 12 months ago

There has been an ongoing discussion in multiple PRs about how to fix the Homebrew path issue. One notable PR that was merged, offering a more general solution, can be found at https://github.com/ffi/ffi/pull/968

While the fix has been merged, there hasn't been a new release yet. To address the glib problem, I used the master branch of ffi in my Bundler:

gem 'ffi', git: 'https://github.com/ffi/ffi.git', branch: 'master'

If you prefer a more stable commit instead of the latest master, you can specify that. With this solution, there's no need to create symlinks between the arm64 and the Rosetta 2 (x86_64) versions of Homebrew.

guschiavon commented 11 months ago

I did all the fixes but had no luck. Fixed using the command

brew install vips

Maybe this could help1

This has completely thrown my system configuration and now I'm not able to locally run any project that leverages the vips library...

kleisauke commented 11 months ago

While the fix has been merged, there hasn't been a new release yet.

It appears that the Ruby-FFI gem has recently released v1.16.0, which should address this issue.

hiveer commented 10 months ago

In my case, I'm using Mac OS 14.0 with M2, what I did is just to:

  1. brew install glib
  2. brew install vips
thomasbromehead commented 10 months ago

v1.16.0

Still having the issue with ffi 1.16.3 and Ventura 13.5 on an M1 Macbook Air

jcupitt commented 10 months ago

Hi @thomasbromehead,

It was working fine on my M2 mac mini last time I tested it, I'll try again to verify some time this weekend.

I would doublecheck that you are using homebrew ruby and that you have no old x86 homebrew binaries on your system, in case you've not done that.

jcupitt commented 10 months ago

I tried just now on my M2 mac mini, and it all worked. Here's what I did:

  1. I use bash as my shell
  2. I uninstalled all of homebrew to make sure I had a clean slate, I emptied my .bash_profile
  3. Ran the usual /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" to install homebrew
  4. I added homebrew to my path in the usual way.

Here's my .bash_profile:

export CLICOLOR=1

eval "$(/opt/homebrew/bin/brew shellenv)"

I also ran eval "$(/opt/homebrew/bin/brew shellenv)" directly to make sure everything was set up.

  1. I ran brew install vips
  2. I used the apple ruby (2.6.0) for testing, but I'm sure you should use the homebrew one. I ran gem install ruby-vips --user-install to install everything to ~/.gem.

To verify it worked, I tried:

$ irb

WARNING: This version of ruby is included in macOS for compatibility with legacy software.
In future versions of macOS the ruby runtime will not be available by
default, and may require you to install an additional package.

irb(main):002:0> require "vips"
=> true
irb(main):003:0> Vips::Image.black(10,10)
=> #<Image 10x10 uchar, 1 bands, multiband>
irb(main):004:0> ^D

I have the various glib libraries in /opt/homebrew, and nothing in /usr/local:

$ ls /opt/homebrew/lib/libgob*
/opt/homebrew/lib/libgobject-2.0.0.dylib
/opt/homebrew/lib/libgobject-2.0.a
/opt/homebrew/lib/libgobject-2.0.dylib
$ ls /opt/homebrew/lib/libglib*
/opt/homebrew/lib/libglib-2.0.0.dylib /opt/homebrew/lib/libglib-2.0.dylib
/opt/homebrew/lib/libglib-2.0.a
$ ls /opt/homebrew/lib/libvip*
/opt/homebrew/lib/libvips-cpp.42.dylib /opt/homebrew/lib/libvips.42.dylib
/opt/homebrew/lib/libvips-cpp.dylib    /opt/homebrew/lib/libvips.dylib
$ ls /usr/local
$
aristotekean commented 5 months ago

I tried just now on my M2 mac mini, and it all worked. Here's what I did:

  1. I use bash as my shell
  2. I uninstalled all of homebrew to make sure I had a clean slate, I emptied my .bash_profile
  3. Ran the usual /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" to install homebrew
  4. I added homebrew to my path in the usual way.

Here's my .bash_profile:

export CLICOLOR=1

eval "$(/opt/homebrew/bin/brew shellenv)"

I also ran eval "$(/opt/homebrew/bin/brew shellenv)" directly to make sure everything was set up.

  1. I ran brew install vips
  2. I used the apple ruby (2.6.0) for testing, but I'm sure you should use the homebrew one. I ran gem install ruby-vips --user-install to install everything to ~/.gem.

To verify it worked, I tried:

$ irb

WARNING: This version of ruby is included in macOS for compatibility with legacy software.
In future versions of macOS the ruby runtime will not be available by
default, and may require you to install an additional package.

irb(main):002:0> require "vips"
=> true
irb(main):003:0> Vips::Image.black(10,10)
=> #<Image 10x10 uchar, 1 bands, multiband>
irb(main):004:0> ^D

I have the various glib libraries in /opt/homebrew, and nothing in /usr/local:

$ ls /opt/homebrew/lib/libgob*
/opt/homebrew/lib/libgobject-2.0.0.dylib
/opt/homebrew/lib/libgobject-2.0.a
/opt/homebrew/lib/libgobject-2.0.dylib
$ ls /opt/homebrew/lib/libglib*
/opt/homebrew/lib/libglib-2.0.0.dylib /opt/homebrew/lib/libglib-2.0.dylib
/opt/homebrew/lib/libglib-2.0.a
$ ls /opt/homebrew/lib/libvip*
/opt/homebrew/lib/libvips-cpp.42.dylib /opt/homebrew/lib/libvips.42.dylib
/opt/homebrew/lib/libvips-cpp.dylib    /opt/homebrew/lib/libvips.dylib
$ ls /usr/local
$

It worked for me. Macbook M1

ansonhoyt commented 5 months ago

brew reinstall glib fixed it on my M1, so maybe some folks can avoid a bigger reinstall.

Details

My Homebrew packages have been installed to /opt/homebrew with arm64 brew for many months, and vips was working, but I noticed the .dylibs folks mentioned were missing until I reinstalled glib:

# glib is installed but missing dylibs:
$ brew info glib
==> glib: stable 2.80.0 (bottled)
Core application library for C
https://developer.gnome.org/glib/
/opt/homebrew/Cellar/glib/2.80.0_2 (524 files, 36MB)
  Poured from bottle using the formulae.brew.sh API on 2024-03-31 at 19:30:11
...
$ ls /opt/homebrew/lib/libgob*
ls: /opt/homebrew/lib/libgob*: No such file or directory

# Reinstalled and now dylibs are found:
$ brew reinstall glib
$ ls /opt/homebrew/lib/libgob*
/opt/homebrew/lib/libgobject-2.0.0.dylib /opt/homebrew/lib/libgobject-2.0.dylib
/opt/homebrew/lib/libgobject-2.0.a

# Now vips loads without errors again:
$ ruby -e 'require "vips"'

(While I still have a few things installed with a separate x86_64 homebrew install, neither glib nor vips were. That didn't seem to be an issue.)

Yannmm commented 4 months ago

In my case, I'm using Mac OS 14.0 with M2, what I did is just to:

  1. brew install glib
  2. brew install vips

worked for me. I'm using rails 7.1.3 on mac M1 chip.