Home > Software design >  Could not open library 'lib.dylib' on Mac
Could not open library 'lib.dylib' on Mac

Time:06-08

Have some issues with launching ruby tests on Mac(Monterey 12.2.1). I've launched bundle install - everything was finished successfully, after that I tried to do a command bundle exec rake db:test:refresh, and got the following error

LoadError: Couldn't load the GEOS CAPI library.
/Users/alexandra_shimanovich/.bundle/ruby/2.5.0/gems/ffi-geos-0.3.0/lib/ffi-geos.rb:1000:in `rescue in <module:FFIGeos>'
/Users/alexandra_shimanovich/.bundle/ruby/2.5.0/gems/ffi-geos-0.3.0/lib/ffi-geos.rb:982:in `<module:FFIGeos>'
/Users/alexandra_shimanovich/.bundle/ruby/2.5.0/gems/ffi-geos-0.3.0/lib/ffi-geos.rb:51:in `<module:Geos>'
/Users/alexandra_shimanovich/.bundle/ruby/2.5.0/gems/ffi-geos-0.3.0/lib/ffi-geos.rb:7:in `<top (required)>'
/Users/alexandra_shimanovich/Documents/Curb/ride_manager/config/application.rb:9:in `<top (required)>'
/Users/alexandra_shimanovich/Documents/Curb/ride_manager/Rakefile:4:in `require'
/Users/alexandra_shimanovich/Documents/Curb/ride_manager/Rakefile:4:in `<top (required)>'
/Users/alexandra_shimanovich/.rbenv/versions/2.5.5/bin/bundle:23:in `load'
/Users/alexandra_shimanovich/.rbenv/versions/2.5.5/bin/bundle:23:in `<main>'
LoadError: Could not open library '/usr/lib/': dlopen(/usr/lib/, 0x0005): tried: '/usr/lib/' (not a file), '/usr/local/lib/' (not a file).
Could not open library 'lib.dylib': dlopen(lib.dylib, 0x0005): tried: 'lib.dylib' (no such file), '/usr/local/lib/lib.dylib' (no such file), '/usr/lib/lib.dylib' (no such file), '/Users/alexandra_shimanovich/Documents/Curb/ride_manager/lib.dylib' (no such file), '/usr/local/lib/lib.dylib' (no such file), '/usr/lib/lib.dylib' (no such file)

I looked inside ffi-geos.rb

def self.search_paths
      @search_paths ||= begin
        if ENV['GEOS_LIBRARY_PATH']
          [ ENV['GEOS_LIBRARY_PATH'] ]
        elsif FFI::Platform::IS_WINDOWS
          ENV['PATH'].split(File::PATH_SEPARATOR)
        else
          [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}' ]
          [ '/usr/local/{lib64,lib}', '/opt/local/{lib64,lib}', '/usr/{lib64,lib}', '/usr/lib/{x86_64,i386}-linux-gnu' ]
        end
      end
    end

I know that in my computer lib files are not in /usr/local/.. but in /opt/homebrew/lib. But when I looked inside /opt/homebrew/lib I didn't find lib.dylib. There are only libgeos.3.10.2.dylib libgeos.dylib libgeos_c.1.16.0.dylib libgeos_c.1.dylib libgeos_c.dylib.

Please, help me find the right lib and somehow tell ffi-geos.rb to look in the right place, I would REALLY appreciate it! Thank you!

CodePudding user response:

But when I looked inside /opt/homebrew/lib I didn't find lib.dylib

The code from ffi-geos.rb you posted is not looking for lib.dylib (or lib64.dylib), but it's adding /usr/local/lib, /usr/local/lib64, etc, to the search path to look for the specific GEOS dylibs. As your library files are in /opt/homebrew/lib, they won't be found by that automatic procedure.

The first conditional in the code shows you can set an environment variable to define the search path. So, set the library path with:

export GEOS_LIBRARY_PATH=/opt/homebrew/lib

Hope this works!

  • Related