4

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?

shadman Ah
  • 69
  • 1
  • 5

4 Answers4

7

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.


Why it compiles but doesn't run (for linuxbrew)

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

Add library path to ldconfig

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

Symlink it into one of the existing library paths

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)
Alex
  • 16,409
  • 6
  • 40
  • 56
0

Most probably you need to install libffi. On CentOS/RHEL/Fedora systems you will need to execute:

sudo dnf -y install libffi
hmdne
  • 434
  • 2
  • 5
  • I try but isn't solve – shadman Ah Jan 23 '22 at 07:22
  • Can you try this: ``` ldd /home/shadman/.rbenv/versions/3.0.1/lib/ruby/gems/3.0.0/gems/ffi-1.15.5/lib/ffi_c.so ``` What does this output? There you should have your missing library issue. – hmdne Jan 23 '22 at 07:23
0

When I was working on a rails project I realized there was a difference in versions between the system and project one thus my solution was matching the two:

  1. gem uninstall ffi
  2. gem install ffi -v 1.15.0 -- --disable-system-libffi

Ubuntu version (20.04)

-1

Update my ubuntu from 20.04 to 20.10 and install Ruby version 3.0.2 and Ruby On Rails version 7.0.0 . That solved the error.

ouflak
  • 2,458
  • 10
  • 44
  • 49
shadman Ah
  • 69
  • 1
  • 5