libffi.so.8:无法打开共享对象文件

sha*_* Ah 4 ruby ruby-on-rails libffi ruby-on-rails-7

我将 Rails 升级到 7.0.1。当我这样做时rails g controller Pages home,它给出了错误:

>>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>'
Run Code Online (Sandbox Code Playgroud)

知道如何解决这个问题吗?

Ale*_*lex 8

你可以用它自带的ffi内部编译gem 。libffi确保版本与捆绑程序尝试安装的版本匹配:

gem install ffi --version "1.15.5" -- --disable-system-libffi
Run Code Online (Sandbox Code Playgroud)

下面是一些其他解决方案。


为什么它可以编译但不能运行(对于 linuxbrew)

ffi编译时,它会寻找libffi这样的内容:

gem install ffi --version "1.15.5" -- --disable-system-libffi
Run Code Online (Sandbox Code Playgroud)

它返回linuxbrew版本,我认为这是因为pkg-config来自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
Run Code Online (Sandbox Code Playgroud)

在运行时,动态库的查找是不同的:

>> 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"]
Run Code Online (Sandbox Code Playgroud)

您可以使用以下命令查看运行时可用的所有内容ldconfig -p

$ 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
Run Code Online (Sandbox Code Playgroud)

添加库路径到ldconfig

您可以向库查找路径添加另一个路径。只需添加您需要的内容,我尝试添加,/home/linuxbrew/.linuxbrew/lib/但它破坏了我的其他一切:

# /etc/ld.so.conf.d/linuxbrew.conf

/home/linuxbrew/.linuxbrew/Cellar/libffi/3.4.4/lib/
Run Code Online (Sandbox Code Playgroud)

并更新 ld 缓存:

$ 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
...
Run Code Online (Sandbox Code Playgroud)

将其符号链接到现有库路径之一

如果 gem 编译成功,则意味着您libffi.so.8在某处拥有必要的东西。找到它并对其进行符号链接:

$ 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
Run Code Online (Sandbox Code Playgroud)