kevin@Kevins-MacBook-Air ~ % sudo arch -x86_64 gem install ffi
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20220124-41484-17xcahw.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
--without-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=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/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
--enable-system-libffi
--disable-system-libffi
--with-libffi-config
--without-libffi-config
--with-pkg-config
--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header'
from extconf.rb:10:in `system_libffi_usable?'
from extconf.rb:42:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-20/2.6.0/ffi-1.15.5/gem_make.out
kevin@Kevins-MacBook-Air ~ %
You have to install development tools first.
@andesappal Could you check if you have XCode Command Line Tools installed? by runningxcode-select --install
Here’s what I did, this might help you @mareFernando03 :
mkmf.log
file mentioned in the output from the failedffi
installation. For me, this was at/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log
.xcrun clang
command, nearby the-I
parameter. For me this is/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21
universal-darwinXX
directory to see what files you have in there (orcd
/ls
). For me, I could see that I have a directory nameduniversal-darwin22
and none nameduniversal-darwin21
as mentioned in themkmf.log
./Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21
in my case), and symlink it to the correct path (in my case/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22
)ffi
again and it should work. For me, I used this command:arch -x86_64 sudo gem install ffi
I hope this can help some people.
It seems that the build script is using the wrong include directory - universal-darwin19 instead of universal-darwin20. Creating a link for that directory fixed the issue for me.
Mac M1 you need run this command:
sudo arch -arm64 gem install ffi
If you encounter the error “An error occurred while installing ffi (1.15.5), and Bundler cannot continue” while running the command npx react-native@latest init AwesomeProject, try initializing your project in a folder directory without spaces. For example, run npx react-native init on the “Desktop” directory, which usually doesn’t have spaces in its path. This should resolve the issue.
Having the same issue. Adding the symlink did not work. I was just reading this issue and OP hinted at removing spaces in the build path.
Removing the space in the pathname solved my issue.
Disclaimer !! You have to be careful with the next decisions
I was actually getting an error even after doing that, then I had to install another version of ruby using home brew.
brew install ruby
For M1, M2
echo 'export PATH="/opt/homebrew/opt/ruby/bin:/opt/homebrew/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc
For Intel
echo 'export PATH="/usr/local/opt/ruby/bin:/usr/local/lib/ruby/gems/3.2.0/bin:$PATH"' >> ~/.zshrc
The 3.2.0 in the command above assumes Homebrew installed a Ruby version that starts with 3.2. If it installed a different version, replace 3.2 with the first two digits of your Ruby version.
Then “refresh” your shell for these changes to take effect:
source ~/.zshrc
Or you can open a new terminal tab, or quit and restart Terminal.
Replace .zshrc with .bash_profile if you are using Bash. If you’re not sure, read my guide to find out which shell you’re using.
To check that you’re now using the non-system version of Ruby, you can run the following commands:
which ruby
It should not be
/usr/bin/ruby
ruby -v
It should be 3.2.+ or later.
Once you have this new version of Ruby installed, you can now install bundler (or any other gem):
I then install cocoa pod
sudo gem install cocoapods
and everything has been okay since then .
Source
https://github.com/ffi/ffi/issues/937#issuecomment-1368162894
This works, I got confused on last 4th point, so adding it
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin23 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22
Ran into this same issue. Here’s how I fixed mine.
In your
mkmf.log
, you would find the universal-darwinxx file you should have. In my case, it was/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21
Run this command
cd $(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0
to confirm what files you currently have. I found that I had universal-darwin22After you have confirmed that you have a different file, run this command
sudo ln -sf universal-darwin22 universal-darwin21
. This command creates a symbolic link nameduniversal-darwin21
that points touniversal-darwin22
.This should fix the issue
I have a user who ran into this issue today on his Mac M1 based computer. The only steps that were required to fix this were running xcode-select --install and bundle install again.
You might get
Operation not permitted
using this, it’s best to usesudo ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin23 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22
Thanks! In my case it was creating a link universal-darwin21 which directs to universal-darwin22
Same error on Catalina. Development tools are already installed.
Ruby version:
Log:
On my system,
ruby/config.h
is located in/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin20
. Maybe that’s the issue?