Gem::Ext::BuildError: 错误: 无法在 macOS Monterey 上构建 gem 本机扩展

2024-01-25

当我跑步时bundle install在我的 Rails 5 项目中,我在似乎具有本机扩展的 gem 上遇到了许多错误。以下是其中一个 gem 的输出顶部:

Installing nio4r 1.2.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

checking for unistd.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_without_gvl()... yes
checking for sys/select.h... yes
checking for poll.h... yes
checking for sys/epoll.h... no
checking for sys/event.h... yes
checking for sys/queue.h... yes
checking for port.h... no
checking for sys/resource.h... yes
creating Makefile

current directory: /Users/<my-username>/.rvm/gems/ruby-2.7.4/gems/nio4r-1.2.1/ext/nio4r
make "DESTDIR=" clean

current directory: /Users/<my-username>/.rvm/gems/ruby-2.7.4/gems/nio4r-1.2.1/ext/nio4r
make "DESTDIR="
compiling monitor.c
monitor.c:91:24: warning: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Wcompound-token-split-by-macro]
if(interests_id == rb_intern("r")) {
                   ^~~~~~~~~~~~~~
/Users/<my-username>/.rvm/rubies/ruby-2.7.4/include/ruby-2.7.0/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
    __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                  ^
monitor.c:91:24: note: '{' token is here
    if(interests_id == rb_intern("r")) {
                       ^~~~~~~~~~~~~~

我已经尝试了很多事情。

Per 这个帖子 https://stackoverflow.com/questions/42652189/how-to-fix-a-bundle-install-nio4r-error-on-rails-5-0-0我尝试了以下建议:

# didn't fix it
bundle config build.nio4r --with-cflags="-std=c99"
bundle

# didn't fix it
xcode-select --install
sudo xcodebuild -license accept
bundle

我也参考了这个 Go Rails 指南 https://gorails.com/setup/osx/12-monterey,特别是处理需要 C 扩展的 gem 的“最终步骤”部分,但该命令似乎不适用,因为我没有从 Mojave 迁移我的 macOS。

此时我不确定下一步要尝试什么。最终:问题似乎在于无法安装需要 C 扩展的 gem。

环境:

  • macOS 蒙特利版本12.2
  • 将 rvm 与 ruby​​ 版本一起使用2.7.4
  • 项目使用的是rails版本5.0.1

事实证明问题在于Gemfile.lock文件,它被锁定为使用旧版本bundler。我们只是删除了Gemfile.lock,并重新运行bundle重生Gemfile.lock。这解决了它。现在它在底部这样说Gemfile.lock文件,所以它喜欢这个版本的捆绑器:

BUNDLED WITH
   2.3.9
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Gem::Ext::BuildError: 错误: 无法在 macOS Monterey 上构建 gem 本机扩展 的相关文章

随机推荐