13

I'm having troubles to do bundle install in one project I get to work on in Rails 4.2.10. When I bundle I receive the next error:

An error occurred while installing ffi (1.9.25), and Bundler cannot continue. Make sure that gem install ffi -v '1.9.25' succeeds before bundling.

In Gemfile:
  s3_direct_upload was resolved to 0.1.6, which depends on
    sass-rails was resolved to 5.0.7, which depends on
      sass was resolved to 3.6.0, which depends on
        sass-listen was resolved to 4.0.0, which depends on
          rb-inotify was resolved to 0.9.10, which depends on
            ffi

When I run gem install ffi -v '1.9.25' also an error occurs:

Building native extensions. This could take a while...
ERROR:  Error installing ffi:
    ERROR: Failed to build gem native extension.

    current directory: /xxx/xxx/.rvm/gems/ruby-2.5.3/gems/ffi-1.9.25/ext/ffi_c
/xxx/xxx/.rvm/rubies/ruby-2.5.3/bin/ruby -r ./siteconf20190110-6923-1jimorr.rb extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... yes
checking for ffi_call() in -lffi... yes
checking for ffi_closure_alloc()... no
checking for ffi_raw_call()... no
checking for shlwapi.h... no
checking for ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
creating extconf.h
creating Makefile

current directory: /xxx/xxx/.rvm/gems/ruby-2.5.3/gems/ffi-1.9.25/ext/ffi_c
make "DESTDIR=" clean

current directory: /xxx/xxx/.rvm/gems/ruby-2.5.3/gems/ffi-1.9.25/ext/ffi_c
make "DESTDIR="
Configuring libffi
clang: error: unsupported option '-print-multi-os-directory'
clang: error: no input files
cd "/xxx/xxx/.rvm/gems/ruby-2.5.3/gems/ffi-1.9.25/ext/ffi_c/libffi-x86_64-darwin18" && /Volumes/Macintosh HD/Applications/Xcode.app/Contents/Developer/usr/bin/make
/bin/sh: /Volumes/Macintosh: No such file or directory
make: *** ["/xxx/xxx/.rvm/gems/ruby-2.5.3/gems/ffi-1.9.25/ext/ffi_c/libffi-x86_64-darwin18"/.libs/libffi_convenience.a] Error 127

make failed, exit code 2

Gem files will remain installed in /xxx/xxx/.rvm/gems/ruby-2.5.3/gems/ffi-1.9.25 for inspection.
Results logged to /xxx/xxx/.rvm/gems/ruby-2.5.3/extensions/x86_64-darwin-18/2.5.0/ffi-1.9.25/gem_make.out

I've been trying many solutions online but cannot resolve this issue. Seems the issue is with my system as I'm new to the team and the other developers were unable to help me as they do not have this kind of issue.

Jakub
  • 2,367
  • 6
  • 31
  • 82
  • see answers in: https://stackoverflow.com/questions/7852566/error-error-installing-ffi-error-failed-to-build-gem-native-extension maybe some will help – mrzasa Jan 10 '19 at 10:34
  • I'm on a mac and I tried to put in my gem file the ffi but I was asked to delete as the master gemfile doesn't contain the ffi. There are other solutions? – Jakub Jan 10 '19 at 10:45
  • General tip: you miss some native dependencies (libraries) and you need to install them. You don't need to alter the gemfile, to test if it's OK just run `gem install ffi -v '1.9.25'` (just as you did) – mrzasa Jan 10 '19 at 10:53
  • So as I showed above doing that gives always the same error. Please check the last part of my question – Jakub Jan 10 '19 at 10:56
  • That the error: ` gem install ffi -v '1.9.25' Building native extensions. This could take a while... ERROR: Error installing ffi: ERROR: Failed to build gem native extension. ` – Jakub Jan 10 '19 at 10:58
  • yeah, I just point that it's a good way of testing it (and altering gemfile is not) – mrzasa Jan 10 '19 at 11:06
  • Ok but without resolving this I'm unable to do the bundle and work on the tasks I have I tried many things :( – Jakub Jan 10 '19 at 11:57
  • did you install Mac Developer Tools? `xcode-select --install` – davegson Jan 10 '19 at 12:05
  • Yes I have it installed I have Version 10.0 (10A255) – Jakub Jan 10 '19 at 12:11

3 Answers3

15

I was able to successfully install ffi with the following command:

LDFLAGS="-L/usr/local/opt/libffi/lib" PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" gem install ffi -v '1.9.25'

Found on some japanese board

Jacques
  • 151
  • 1
  • 3
1

According to the libffi README, only GCC is a tested compiler on macOS. You are using Clang, which doesn't support the command line option -print-multi-os-directory.

You need to either patch libffi to work with Clang, or use GCC.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
1

Your error is the following Configuring libffi clang: error: unsupported option '-print-multi-os-directory' clang: error: no input files because Clang (wich is the C compiler you are using) doesn't support the option '-print-multi-os-directory'.

Could you check that X-Code command line tools are perfectly installed by executing the following command? xcode-select --install

Also would you mind to try brew install automake autoconf libtool libffi to install required dependencies?

  • xcode-select: error: command line tools are already installed, use "Software Update" to install updates All is installed already. Brew also installed. – Jakub Jan 10 '19 at 13:16
  • Do you have automake autoconf libtool and libffi installed? – Armand Fardeau Jan 10 '19 at 13:27
  • Yes all is installed Warning: automake 1.16.1_1 is already installed and up-to-date To reinstall 1.16.1_1, run `brew reinstall automake` Warning: autoconf 2.69 is already installed and up-to-date To reinstall 2.69, run `brew reinstall autoconf` Warning: libtool 2.4.6_1 is already installed and up-to-date To reinstall 2.4.6_1, run `brew reinstall libtool` Warning: libffi 3.2.1 is already installed and up-to-date To reinstall 3.2.1, run `brew reinstall libffi` – Jakub Jan 10 '19 at 14:04
  • Then maybe you will have to give a try to GCC with `brew install gcc`. More instructions on how to configure it : https://stackoverflow.com/questions/28970935/osx-replace-gcc-version-4-2-1-with-4-9-installed-via-homebrew/28982564#28982564 – Armand Fardeau Jan 10 '19 at 15:01
  • Sorry I could not helped you, I read somewhere that using another might solve your issue. – Armand Fardeau Jan 10 '19 at 15:31