Fpm: OS X El Capitan breaks fpm: Could not open library 'libc.dylib'

Created on 16 Sep 2015  Â·  17Comments  Â·  Source: jordansissel/fpm

This is probably a bug in https://github.com/ffi/ffi, but after upgrading to OS X El Capitan my fpm build of an rpm started failing with below error.

fpm --rpm-os linux -s dir -C app/dist/release -t rpm -n acme-example -v 4.0.0 --iteration 0.alpha1.ged679e1 --vendor ACME --description 'ACME example app' --url http://www.example.com --before-install scripts/service-stop.sh --after-install scripts/service-restart.sh --after-remove scripts/service-restart.sh --before-remove scripts/service-stop.sh --rpm-auto-add-directories -x '*/.svn' -x '*/.git' -x '*/.gitkeep' -x '*/.idea' -x '*/.jets3t-ignore' -x '*~' .=/opt/acme/example
/Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'libc.dylib': dlopen(libc.dylib, 5): image not found (LoadError)
    from /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10/lib/ffi/library.rb:100:in `map'
    from /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10/lib/ffi/library.rb:100:in `ffi_lib'
    from /Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/lib/fpm/util.rb:8:in `<module:Util>'
    from /Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/lib/fpm/util.rb:6:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/lib/fpm/package.rb:2:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/lib/fpm.rb:3:in `<top (required)>'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:69:in `require'
    from /Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/bin/fpm:5:in `<top (required)>'
    from /usr/local/bin/fpm:23:in `load'
    from /usr/local/bin/fpm:23:in `<main>'

The below change to util.rb seems to fix it:

*** /sudo:[email protected]:/Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/lib/fpm/util.rb~
--- /sudo:[email protected]:/Library/Ruby/Gems/2.0.0/gems/fpm-1.4.0/lib/fpm/util.rb
***************
*** 5,11 ****
  # Some utility functions
  module FPM::Util
    extend FFI::Library
!   ffi_lib FFI::Library::LIBC

    # mknod is __xmknod in glibc a wrapper around mknod to handle
    # various stat struct formats. See bits/stat.h in glibc source
--- 5,14 ----
  # Some utility functions
  module FPM::Util
    extend FFI::Library
!   ffi_lib '/usr/lib/libc.dylib'
!   # THE ORIGINAL LINE FAILS ON OSX EL CAPITAN:
!   # ffi_lib FFI::Library::LIBC
!   # /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'libc.dylib': dlopen(libc.dylib, 5): image not found (LoadError)

    # mknod is __xmknod in glibc a wrapper around mknod to handle
    # various stat struct formats. See bits/stat.h in glibc source

Most helpful comment

This did the trick for me:

brew install ruby
sudo gem uninstall fpm
sudo gem install fpm

All 17 comments

Dang it, just ran into this.

Also ran into this.

Me too

me to

Any updates on how to fix this? Just came across it was well out of the blue... Also running El Capitan

Simply opening the XCode application and agreeing to (apparently) newly published terms seemed to get rid of the error. Guess it was some block on the developer tools.

I can't upgrade to El Capitan yet,so i will rely on y'all to debug and test
this. Good luck :)

On Tuesday, October 27, 2015, otownsend92 [email protected] wrote:

Simply opening the XCode application and agreeing to (apparently) newly
published terms seemed to get rid of the error. Guess it was some block on
the developer tools.

—
Reply to this email directly or view it on GitHub
https://github.com/jordansissel/fpm/issues/1010#issuecomment-151399228.

@otownsend92 are you sure it's related to XCode? The root problem is reproduced in https://github.com/ffi/ffi/issues/461. I still see the below error when using ffi_lib FFI::Library::LIBC. I've opened XCode 7.1 and clicked Agree, etc but that doesn't seem to affect this problem. Using ffi_lib '/usr/lib/libc.dylib' does workaround the problem.

/Library/Ruby/Gems/2.0.0/gems/ffi-1.9.10/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'libc.dylib': dlopen(libc.dylib, 5): image not found (LoadError)

@jamshid

Ah okay, it was for me. Below is the error I received. Notice the line "You have to install development tools first." I tried executing 'xcode-select install' but was told everything was up to date. I guess I was running into something a little different. Apologies!

Error: ===============

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

/Users/username/.rvm/rubies/ruby-2.2.1/bin/ruby -r ./siteconf20151027-13394-1w54ixg.rb extconf.rb

checking for ffi.h... * extconf.rb failed *
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/username/.rvm/rubies/ruby-2.2.1/bin/$(RUBY_BASE_NAME)
--with-ffi_c-dir
--without-ffi_c-dir
--with-ffi_c-include
--without-ffi_c-include=${ffi_c-dir}/include
--with-ffi_c-lib
--without-ffi_c-lib=${ffi_c-dir}/lib
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:456:in try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:587:intry_cpp'
from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:1060:in block in have_header' from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:911:inblock in checking_for'
from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:351:in block (2 levels) in postpone' from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:321:inopen'
from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:351:in block in postpone' from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:321:inopen'
from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:347:in postpone' from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:910:inchecking_for'
from /Users/username/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/mkmf.rb:1059:in have_header' from extconf.rb:16:in

'

extconf failed, exit code 1

Gem files will remain installed in /Users/username/.rvm/gems/ruby-2.2.1/gems/ffi-1.9.10 for inspection.
Results logged to /Users/username/.rvm/gems/ruby-2.2.1/extensions/x86_64-darwin-15/2.2.0/ffi-1.9.10/gem_make.out
An error occurred while installing ffi (1.9.10), and Bundler cannot continue.
Make sure that gem install ffi -v '1.9.10' succeeds before bundling.

+1

Same error.

Agreeing to the Xcode license doesn't fix the error.

Installing Xcode command line tools doesn't fix the error.

Mac OS X El Capitan 10.11.1

+1 have encountered

It seems the content of the path causes the FFI library loading to fail on OS X.

I tried loading a library from it's full and original path:

require 'ffi'
module Hello
    extend FFI::Library
    ffi_lib "Users/USERNAME/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/argon2-0.1.1/ext/argon2_wrap/libargon2_wrap.dylib"
end
 # => FAILS to load library

I copied the compiled library to my desktop and loaded it using FFI and a clean path:

require 'ffi'
module Hello
    extend FFI::Library
    ffi_lib "/Users/USERNAME/Desktop/libargon2_wrap.dylib"
end
# => Success, the library loaded

I hope this helps with resolving the issue.

+1 Same problem

@otownsend92 I'm was getting the same exact error you did. When I did an rvm list, I saw that I was pointing to ruby-1.9.3-p545. I upped it to ruby-19.3-p551 (the latest version, I guess), and then my bundle command started working again, without the ffi error.

Also updated ruby and installed fpm again and it worked like a sharm for me.

This did the trick for me:

brew install ruby
sudo gem uninstall fpm
sudo gem install fpm

Check this solution from @ethicalhack3r.

https://github.com/wpscanteam/wpscan/issues/877#issuecomment-149681462

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samueljc picture samueljc  Â·  4Comments

leandro-lucarella-sociomantic picture leandro-lucarella-sociomantic  Â·  10Comments

vadi2 picture vadi2  Â·  3Comments

jameshfisher picture jameshfisher  Â·  7Comments

jean-christophe-manciot picture jean-christophe-manciot  Â·  4Comments