I would like to know how to resolve next error seen when executed require
command on the console after installed Ruby 2.2.1
Windows installer and Ruby gem 2.4.6
.
LoadError: cannot load such file -- ffi_c
from C:/Ruby22-x64/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_req
uire.rb:54:in `require'
Is this something like DLL?
If you read the requirement documentation for ffi
, you can see:
You need a sane building environment in order to compile the extension. At a minimum, you will need:
- A C compiler (e.g. Xcode on OSX, gcc on everything else)
- libffi development library - this is commonly in the libffi-dev or libffi-devel
This means the gem is not pre-compiled, and has to compile code when it installs. Which in turn means if you are running on a PC you will need to install the Ruby development kit for windows, aka 'devkit', you can get it from the downloads page on the rubyinstaller site
Download and install devkit first, then open a new command line window followed by:
gem install ffi
Refer to this SO for details: https://stackoverflow.com/a/7988119/3035830
I think there is a minor mistake in ffi's regex in C:\Ruby22-x64\lib\ruby\gems\2.2.0\gems\ffi-1.9.8-x64-mingw32\lib\ffi.rb which makes it incorrectly think you are running ruby 2.1.x
it tests for RUBY_VERSION =~ /2.1/ which catches '2.2.1' whereas it should test for RUBY_VERSION =~ /^2.1/ with a start of line character in.
it should be:
if RUBY_VERSION =~ /^1\.8/
require '1.8/ffi_c'
elsif RUBY_VERSION =~ /^1\.9/
require '1.9/ffi_c'
elsif RUBY_VERSION =~ /^2\.0/
require '2.0/ffi_c'
elsif RUBY_VERSION =~ /^2\.1/
require '2.1/ffi_c'
elsif RUBY_VERSION =~ /^2\.2/
require '2.2/ffi_c'
else
require 'ffi_c'
end
I see that it has now been fixed https://github.com/ffi/ffi/commit/4168ef3dbd56a7b52978efb2ff7d0dc448f8f8f1
Entire error I got as below, but on Mac:
/Users/mayuresh.srivastava/.rvm/gems/ruby-2.7.3/gems/ffi-1.15.4/lib/ffi.rb:3:in `require': cannot load such file -- 2.7/ffi_c (LoadError)
/Users/mayuresh.srivastava/.rvm/gems/ruby-2.7.3/gems/ffi-1.15.4/lib/ffi.rb:5:in `require': dlopen(/Users/mayuresh.srivastava/.rvm/gems/ruby-2.7.3/gems/ffi-1.15.4/lib/ffi_c.bundle, 9): Library not loaded: /opt/homebrew/opt/libffi/lib/libffi.7.dylib (LoadError)
Referenced from: /Users/mayuresh.srivastava/.rvm/gems/ruby-2.7.3/gems/ffi-1.15.4/lib/ffi_c.bundle
Reason: image not found - /Users/mayuresh.srivastava/.rvm/gems/ruby-2.7.3/gems/ffi-1.15.4/lib/ffi_c.bundle
I checked ffi, it was already there:
mayuresh.srivastava$ gem list ffi
*** LOCAL GEMS ***
ffi (1.15.4)
public_suffix (4.0.6)
Still I installed ffi again, and it worked.
mayuresh.srivastava$ gem install ffi
Building native extensions. This could take a while...
Successfully installed ffi-1.15.4
Parsing documentation for ffi-1.15.4
Installing ri documentation for ffi-1.15.4
Done installing documentation for ffi after 11 seconds
1 gem installed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With