Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Please use $HOMEBREW_PREFIX and/or brew --prefix to add a library path #1030

@xeron

Description

@xeron

Hi!

I'm struggling with making ruby-vips/ffi work with custom Homebrew location on Intel mac:

$ brew --prefix
/opt/brew
$ echo $HOMEBREW_PREFIX
/opt/brew

It fails with:

$ bundle exec rails c
Loading development environment (Rails 7.0.4.3)
3.2.2 :001 > require 'vips'
…/bundle/ruby/3.2.0/gems/ffi-1.15.5/lib/ffi/library.rb:145:in `block in ffi_lib': Could not open library 'glib-2.0.0': dlopen(glib-2.0.0, 0x0005): tried: 'glib-2.0.0' (no such file), '/System/Volumes/Preboot/Cryptexes/OSglib-2.0.0' (no such file), '/usr/lib/glib-2.0.0' (no such file, not in dyld cache), 'glib-2.0.0' (no such file), '/usr/local/lib/glib-2.0.0' (no such file), '/usr/lib/glib-2.0.0' (no such file, not in dyld cache). (LoadError)
Could not open library 'libglib-2.0.0.dylib': dlopen(libglib-2.0.0.dylib, 0x0005): tried: 'libglib-2.0.0.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibglib-2.0.0.dylib' (no such file), '/usr/lib/libglib-2.0.0.dylib' (no such file, not in dyld cache), 'libglib-2.0.0.dylib' (no such file), '/usr/local/lib/libglib-2.0.0.dylib' (no such file), '/usr/lib/libglib-2.0.0.dylib' (no such file, not in dyld cache)

Setting the following doesn't help:

$ export LD_LIBRARY_PATH=/opt/brew/lib
$ export DYLD_LIBRARY_PATH=/opt/brew/lib
$ export DYLD_FALLBACK_LIBRARY_PATH=/opt/brew/lib

In fact I think ruby sets DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH to nil on load:

$ export DYLD_FALLBACK_LIBRARY_PATH=/opt/brew/lib
$ echo $DYLD_FALLBACK_LIBRARY_PATH
/opt/brew/lib
$ export DYLD_LIBRARY_PATH=/opt/brew/lib
$ echo $DYLD_LIBRARY_PATH
/opt/brew/lib
$ irb
3.2.2 :001 > ENV['DYLD_FALLBACK_LIBRARY_PATH']
 => nil
3.2.2 :002 > ENV['DYLD_LIBRARY_PATH']
 => nil

I saw a discussion in #968 about using ENV['HOMEBREW_PREFIX'] or brew --prefix shellout to get an extra library path and I think this would solve my issue.

Using ffi from the master branch didn't fix the issue. I've added the following code to dynamic_library.rb as an experiment:

    unless ENV['HOMEBREW_PREFIX'].to_s.empty?
      SEARCH_PATH << File.join(ENV['HOMEBREW_PREFIX'], 'lib')
    end

and it finally worked.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions