当我在rails 5项目上运行bundle install时,我在gems上遇到了一些错误,这些错误似乎是本机扩展的.以下是其中一个Ruby 的输出顶部:

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")) {
                       ^~~~~~~~~~~~~~

我试过很多方法.

this post人中,我try 了以下建议:

# 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

我还提到了this Go Rails guide,特别是"最终步骤"部分,该部分处理需要C扩展的GEM,但该命令似乎不适用,因为我没有从Mojave迁移macOS.

现在我不确定下一步该怎么做.最终:问题似乎是无法安装需要C扩展的gems.

环境:

  • macOS Monterey 12.2
  • 在ruby version 2.7.4中使用rvm
  • 该项目使用的是rails版本5.0.1

推荐答案

问题是,在Gemfile.lock文件中,它被锁定为使用旧版本的bundler.我们只是删除了Gemfile.lock,然后重新运行bundle以重新生成Gemfile.lock.这就解决了问题.它现在在Gemfile.lock文件的底部说了这句话,所以它喜欢这个版本的bundler:

BUNDLED WITH
   2.3.9

Ruby-on-rails相关问答推荐

仅当未在带有ENV[';Dyno';]的Heroku问题上运行时才初始化Sidekiq Cron

Rails7--如何使用内联代码仅为操作运行BEFORE操作

我try 使用Ruby on Rails7创建一个Carbon 足迹计算器.但我无法保存和用户S对象

Rails + Turbo_stream自定义操作:我可以在没有Stimulus的情况下根据DOM状态做出有条件的响应吗?

在Rails中,如何将帮助器方法添加到属性/列?

在Ruby中按特定值合并时,将两个对象数组添加到一起

Rails 7 - has_many_attached 在加载新附件时删除旧附件

Rails 7 应用程序 - 引用模型文件时出现未初始化常量错误

Rails 是否带有未授权异常?

Rails 4.1 Mailer 预览和设计自定义邮箱

Ruby - ActiveRecord::ConnectionNotEstablished

如何避免 has_many :through 关系中的重复?

Ruby on Rails 中的消息队列

如何独立测试模型的回调方法?

Rails 5:无法从参数中检索哈希值

测试:如何在不损失速度的情况下专注于行为而不是执行?

加载常量时自动加载常量时检测到循环依赖

在 Rails 协会中未找到名为的协会可能拼写错误的问题

使用 heroku 和 namecheap 设置自定义域

Ruby on Rails:如何在 select_tag 中使用默认占位符?