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

9rbhqvlz  于 2023-05-06  发布在  Ruby
关注(0)|答案(2)|浏览(214)

当我在我的rails 5项目上运行bundle install时,我在gems上遇到了许多错误,这些错误似乎有原生扩展。下面是其中一个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")) {
                       ^~~~~~~~~~~~~~

我试过很多方法。
this post我尝试了以下建议:

# 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,但该命令似乎不适用,因为我没有从莫哈韦迁移我的macOS。
在这一点上,我不知道下一步该做什么。最终:看起来这个问题围绕着无法安装需要C扩展的gem。
环境:

  • macOS Monterey版本12.2
  • 使用rvm与ruby版本2.7.4
  • 项目正在使用Rails版本5.0.1
ql3eal8s

ql3eal8s1#

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

BUNDLED WITH
   2.3.9
ulmd4ohb

ulmd4ohb2#

你试过这个吗?对我很有效

brew install openssl

gem install eventmachine -- --with-cppflags=-I/usr/local/opt/openssl@1.1/include

然后运行bundle install

相关问题