Gem::Ext::BuildError: 错误: 当我运行捆绑安装时无法构建 gem 本机扩展

问题描述 投票:0回答:1

有关我的环境的一些详细信息:

  • Ruby版本:Ruby 3.2.0
  • RubyGems 版本:3.5.6
  • rbenv版本:1.2.0
  • MacOS:索诺玛 14.1.2 / M2

我正在尝试运行 bundle install 为我的项目安装 gem,但出现以下错误:

Installing unicode 0.4.4.4 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/unicode-0.4.4.4/ext/unicode
/Users/john.doe/.rbenv/versions/3.2.0/bin/ruby -I /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0 extconf.rb --with-cflags\=-Wno-error\=implicit-function-declaration
creating Makefile

current directory: /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/unicode-0.4.4.4/ext/unicode
make DESTDIR\= sitearchdir\=./.gem.20240308-48017-ak1bt1 sitelibdir\=./.gem.20240308-48017-ak1bt1 clean

current directory: /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/unicode-0.4.4.4/ext/unicode
make DESTDIR\= sitearchdir\=./.gem.20240308-48017-ak1bt1 sitelibdir\=./.gem.20240308-48017-ak1bt1
compiling unicode.c
unicode.c:37:7: warning: 'RB_OBJ_TAINTED' is deprecated: taintedness turned out to be a wrong idea. [-Wdeprecated-declarations]
  if (OBJ_TAINTED(src))
      ^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/fl_type.h:151:25: note: expanded from macro 'OBJ_TAINTED'
#define OBJ_TAINTED     RB_OBJ_TAINTED     /**< @old{RB_OBJ_TAINTED} */
                        ^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/fl_type.h:118:30: note: expanded from macro 'RB_OBJ_TAINTED'
#define RB_OBJ_TAINTED       RB_OBJ_TAINTED
                             ^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/fl_type.h:812:1: note: 'RB_OBJ_TAINTED' has been explicitly marked deprecated here
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/attr/deprecated.h:36:53: note: expanded from macro 'RBIMPL_ATTR_DEPRECATED'
# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
                                                    ^
unicode.c:38:5: warning: 'RB_OBJ_TAINT' is deprecated: taintedness turned out to be a wrong idea. [-Wdeprecated-declarations]
    OBJ_TAINT(obj);
    ^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/fl_type.h:149:25: note: expanded from macro 'OBJ_TAINT'
#define OBJ_TAINT       RB_OBJ_TAINT       /**< @old{RB_OBJ_TAINT} */
                        ^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/fl_type.h:116:30: note: expanded from macro 'RB_OBJ_TAINT'
#define RB_OBJ_TAINT         RB_OBJ_TAINT
                             ^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/fl_type.h:843:1: note: 'RB_OBJ_TAINT' has been explicitly marked deprecated here
RBIMPL_ATTR_DEPRECATED(("taintedness turned out to be a wrong idea."))
^
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/attr/deprecated.h:36:53: note: expanded from macro 'RBIMPL_ATTR_DEPRECATED'
# define RBIMPL_ATTR_DEPRECATED(msg) __attribute__((__deprecated__ msg))
                                                    ^
unicode.c:1039:20: error: incompatible function pointer types passing 'VALUE (get_categories_param *)' (aka 'unsigned long (struct _get_categories_param *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
  return rb_ensure(get_categories_internal, (VALUE)&param,
                   ^~~~~~~~~~~~~~~~~~~~~~~
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/iterator.h:425:25: note: passing argument to parameter 'b_proc' here
VALUE rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2);
                        ^
unicode.c:1040:20: error: incompatible function pointer types passing 'VALUE (WString *)' (aka 'unsigned long (struct _WString *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
                   get_categories_ensure, (VALUE)&wstr);
                   ^~~~~~~~~~~~~~~~~~~~~
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/iterator.h:425:62: note: passing argument to parameter 'e_proc' here
VALUE rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2);
                                                             ^
unicode.c:1057:20: error: incompatible function pointer types passing 'VALUE (get_categories_param *)' (aka 'unsigned long (struct _get_categories_param *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
  return rb_ensure(get_categories_internal, (VALUE)&param,
                   ^~~~~~~~~~~~~~~~~~~~~~~
/Users/john.doe/.rbenv/versions/3.2.0/include/ruby-3.2.0/ruby/internal/iterator.h:425:25: note: passing argument to parameter 'b_proc' here
VALUE rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2);
                        ^
unicode.c:1058:20: error: incompatible function pointer types passing 'VALUE (WString *)' (aka 'unsigned long (struct _WString *)') to parameter of type 'VALUE (*)(VALUE)' (aka 'unsigned long (*)(unsigned long)') [-Wincompatible-function-pointer-types]
                   get_categories_ensure, (VALUE)&wstr);
                   ^~~~~~~~~~~~~~~~~~~~~
.
.
.
2 warnings and 6 errors generated.
make: *** [unicode.o] Error 1

make failed, exit code 2

Gem files will remain installed in /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/unicode-0.4.4.4 for inspection.
Results logged to /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/extensions/arm64-darwin-23/3.2.0/unicode-0.4.4.4/gem_make.out

  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:102:in `run'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:51:in `block in make'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `each'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:43:in `make'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/ext_conf_builder.rb:42:in `build'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:170:in `build_extension'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:204:in `block in build_extensions'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:201:in `each'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/ext/builder.rb:201:in `build_extensions'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/site_ruby/3.2.0/rubygems/installer.rb:843:in `build_extensions'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/rubygems_gem_installer.rb:76:in `build_extensions'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/rubygems_gem_installer.rb:28:in `install'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-2.5.6/lib/bundler/source/rubygems.rb:205:in `install'
  /Users/john.doe/.rbenv/versions/3.2.0/lib/ruby/gems/3.2.0/gems/bundler-.
.
.
An error occurred while installing unicode (0.4.4.4), and Bundler cannot continue.

我非常感谢您提供的任何帮助。 谢谢。

  • 我尝试“xcode-select --install”来检查是否缺少某些内容
  • 我尝试使用 asdf 版本管理器来检查问题是否与 rbenv 相关
ruby rubygems bundler rubymine rbenv
1个回答
0
投票

您遇到的错误,

Gem::Ext::BuildError: ERROR: Failed to build gem native extension
,通常表示编译 gem 的本机扩展时出现问题。这可能是由于多种原因造成的,例如缺少开发工具或版本不兼容。以下是可能解决该问题的几个步骤:

  1. 确保已安装开发工具: 由于您已经尝试过

    xcode-select --install
    ,看来您已经安装了 Xcode 命令行工具。但是,验证或重新安装它们可能会有所帮助,因为有时它们可能未正确设置。

  2. 检查 Ruby 和 Gem 兼容性: 确保您尝试安装的 unicode gem 版本与 Ruby 3.2.0 兼容。您可以检查 gem 的文档或 RubyGems.org 页面以获取兼容性信息。 考虑将 RubyGems (

    gem update --system
    ) 更新到最新版本,因为它有时可以解决安装 gem 的问题。

  3. 安装 macOS 缺少的标头: 在较新版本的 macOS 上,您可能需要安装其他标头。您可以尝试安装这些标头,看看是否可以解决问题:

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
  1. 设置
    SDKROOT
    环境变量: 在 macOS 上,尤其是较新的版本,设置
    SDKROOT
    环境变量有时可以解决编译问题。您可以通过运行来设置它:
export SDKROOT=$(xcrun --show-sdk-path)

设置完毕后,尝试再次运行

bundle install

© www.soinside.com 2019 - 2024. All rights reserved.