ruby-on-rails 无效的ELF头-/usr/local/rvm/gems/ruby-3.2.1/gems/nio4r-2.5.9/lib/nio4r_ext.so(LoadError)

ulydmbyx  于 2023-04-08  发布在  Ruby
关注(0)|答案(1)|浏览(149)

我不知道如何解决这个问题,无法在网上找到信息来帮助,但我发现这是与nio4r宝石,但没有太多其他。请帮助,让我知道我能做什么,任何更多的信息。我使用的是fedora,linux。

[ben@localhost-live hello_app]$ rails s
    => Booting Puma
    => Rails 7.0.4.3 application starting in development 
    => Run `bin/rails server --help` for more startup options
    Puma starting in single mode...
    * Puma version: 5.6.5 (ruby 3.2.1-p31) ("Birdie's Version")
    *  Min threads: 5
    *  Max threads: 5
    *  Environment: development
    *          PID: 33779
    * Listening on http://127.0.0.1:3000
    * Listening on http://[::1]:3000
    Exiting
    <internal:/usr/local/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': /usr/local/rvm/gems/ruby-3.2.1/gems/nio4r-2.5.9/lib/nio4r_ext.so: invalid ELF header - /usr/local/rvm/gems/ruby-3.2.1/gems/nio4r-2.5.9/lib/nio4r_ext.so (LoadError)
        from <internal:/usr/local/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/nio4r-2.5.9/lib/nio.rb:42:in `<main>'
        from <internal:/usr/local/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/usr/local/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/zeitwerk-2.6.7/lib/zeitwerk/kernel.rb:38:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/puma-5.6.5/lib/puma/reactor.rb:24:in `initialize'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/puma-5.6.5/lib/puma/server.rb:244:in `new'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/puma-5.6.5/lib/puma/server.rb:244:in `run'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/puma-5.6.5/lib/puma/single.rb:53:in `run'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/puma-5.6.5/lib/puma/launcher.rb:193:in `run'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/puma-5.6.5/lib/rack/handler/puma.rb:72:in `run'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/rack-2.2.6.4/lib/rack/server.rb:327:in `start'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:38:in `start'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:143:in `block in perform'
        from <internal:kernel>:90:in `tap'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands/server/server_command.rb:134:in `perform'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/thor-1.2.1/lib/thor/command.rb:27:in `run'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/thor-1.2.1/lib/thor/invocation.rb:127:in `invoke_command'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/thor-1.2.1/lib/thor.rb:392:in `dispatch'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/command/base.rb:87:in `perform'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/command.rb:48:in `invoke'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/railties-7.0.4.3/lib/rails/commands.rb:18:in `<main>'
        from <internal:/usr/local/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:/usr/local/rvm/rubies/ruby-3.2.1/lib/ruby/site_ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from /usr/local/rvm/gems/ruby-3.2.1/gems/bootsnap-1.16.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from bin/rails:4:in `<main>'
    [ben@localhost-live hello_app]$
nkkqxpd9

nkkqxpd91#

当本地扩展编译不正确时会出现此问题。您需要重新编译nio4r gem的本地扩展。有很多很多可能的原因导致此问题:
1.您通过传递无效参数(例如,告诉它为错误的体系结构进行编译)来编译扩展
1.您在另一个操作系统上编译了扩展,然后手动将它们移到这个系统上
1.您在过去编译了扩展,然后进行了一次主要的系统升级或操作系统更改,然后试图继续使用以前编译的扩展
还有其他可能的原因,但最直接的解决方案是重新编译扩展:

bundle pristine nio4r

如果您仍然有问题,请确保您的bundler平台是ruby,并且只有ruby

bundle config force_ruby_platform true

这将产生以下效果:
忽略当前机器的平台,只安装ruby平台的gem。因此,具有本机扩展的gem将从源代码编译。
然后重试bundle pristine nio4r以强制重新编译。

相关问题