I upgraded Rails to 7.0.1. When I do the rails g controller Pages home, it's giving the error:
>>rails g controller Pages home
/home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require': libffi.so.8: cannot open shared object file: No such file or directory - /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/ffi-1.15.5/lib/ffi_c.so (LoadError)
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/ffi-1.15.5/lib/ffi.rb:5:in `rescue in <main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/ffi-
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/sassc-2.4.0/lib/sassc.rb:31:in `<main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootstrap-5.1.3/lib/bootstrap/engine.rb:4:in `<main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/sassc-2.4.0/lib/sassc/native.rb:3:in `<main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/sassc-rails-2.1.2/lib/sassc/rails.rb:5:in `<main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bundler-2.3.5/lib/bundler.rb:176:in `require'
from /home/shadman/instagram/config/application.rb:7:in `<main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.1/lib/rails/command/actions.rb:22:in `require_application!'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.1/lib/rails/command/actions.rb:14:in `require_application_and_environment!'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.1/lib/rails/commands/generate/generate_command.rb:21:in `perform'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.1/lib/rails/command.rb:48:in `invoke'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/railties-7.0.1/lib/rails/commands.rb:18:in `<main>'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/bootsnap-1.10.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
from bin/rails:4:in `<main>'
Any idea how to fix this?
You can compile ffi gem with internal libffi that comes with it. Make sure the version matches the one that bundler is trying to install:
gem install ffi --version "1.15.5" -- --disable-system-libffi
Some other solutions below.
When ffi is compiling it's looking for libffi like this:
>> require "mkmf"
>> pkg_config("libffi")
=> ["-I/home/linuxbrew/.linuxbrew/Cellar/libffi/3.4.4/include ", "-L/home/linuxbrew/.linuxbrew/Cellar/libffi/3.4.4/lib/../lib", "-lffi"]
Which returns linuxbrew version, I assume this is because pkg-config is coming from linuxbrew:
$ which -a pkg-config
/home/linuxbrew/.linuxbrew/bin/pkg-config
/usr/bin/pkg-config
/bin/pkg-config
$ pkg-config --libs libffi
-L/home/linuxbrew/.linuxbrew/Cellar/libffi/3.4.4/lib/../lib -lffi
During runtime, the lookup for dynamic libraries is different:
$ ldd /home/alex/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/ffi-1.15.5/ext/ffi_c/ffi_c.so
linux-vdso.so.1 (0x00007ffea8b22000)
libruby.so.3.1 => /home/alex/.rbenv/versions/3.1.2/lib/libruby.so.3.1 (0x00007f5d04ba8000)
libffi.so.8 => not found
...
You can see everything that's available at runtime with ldconfig -p:
$ ldconfig -p | grep libffi
libffi.so.7 (libc6,x86-64) => /lib/x86_64-linux-gnu/libffi.so.7
libffi.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libffi.so
You can add another path to the library lookup paths. Just add what you need, I tried adding /home/linuxbrew/.linuxbrew/lib/ but it broke everything else for me:
# /etc/ld.so.conf.d/linuxbrew.conf
/home/linuxbrew/.linuxbrew/Cellar/libffi/3.4.4/lib/
and update ld cache:
$ sudo ldconfig
If the gem compiles, that means you have the necessary libffi.so.8 somewhere. Find it and symlink it:
$ cd /usr/lib/x86_64-linux-gnu
$ sudo ln -s /home/linuxbrew/.linuxbrew/lib/libffi.so.8
$ ldd /home/alex/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/ffi-1.15.5/ext/ffi_c/ffi_c.so
libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f03de9ee000)
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