如何修复“错误:无法构建 gem 原生扩展。”在 macOS Mojave 上安装 eventmachine 时

     2023-02-25     58

关键词:

【中文标题】如何修复“错误:无法构建 gem 原生扩展。”在 macOS Mojave 上安装 eventmachine 时【英文标题】:How to fix "ERROR: Failed to build gem native extension." when installing eventmachine on macOS Mojave 【发布时间】:2019-07-06 12:07:12 【问题描述】:

我是 ruby​​ 和命令行的新手。

Ruby -v: ruby​​ 2.3.7p456(2018-03-28 修订版 63024)[universal.x86_64-darwin18]

Mac: Mojave 10.14.2

我正在尝试在我的本地主机上打开我的 Jekyll 博客,这在以前没有给我带来任何问题。但是我跑了

bundle exec jekyll serve

并得到这个错误:

Could not find eventmachine-1.2.7 in any of the sources
Run `bundle install` to install missing gems.

按照建议,然后我运行

bundle install

并得到这个错误:

    Ignoring ffi-1.9.25 because its extensions are not built.  Try: gem pristine ffi --version 1.9.25
Ignoring http_parser.rb-0.6.0 because its extensions are not built.  Try: gem pristine http_parser.rb --version 0.6.0
Fetching gem metadata from https://rubygems.org/...........
Using rake 10.5.0
Using public_suffix 3.0.3
Using addressable 2.5.2
Using bundler 2.0.1
Using colorator 1.1.0
Using concurrent-ruby 1.0.5
Fetching eventmachine 1.2.7
Installing eventmachine 1.2.7 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/name/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/gems/eventmachine-1.2.7/ext
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20190212-57509-l19d0i.rb extconf.rb
--with-cppflags=-I/usr/local/opt/openssl/include
checking for main() in -lcrypto... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=$opt-dir/include
    --with-opt-lib
    --without-opt-lib=$opt-dir/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/$(RUBY_BASE_NAME)
    --with-ssl-dir
    --without-ssl-dir
    --with-ssl-include
    --without-ssl-include=$ssl-dir/include
    --with-ssl-lib
    --without-ssl-lib=$ssl-dir/lib
    --with-openssl-config
    --without-openssl-config
    --with-pkg-config
    --without-pkg-config
    --with-cryptolib
    --without-cryptolib
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:456:in `try_do': The compiler failed to
generate an executable file. (RuntimeError)
You have to install development tools first.
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:535:in `block in try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/tmpdir.rb:89:in `mktmpdir'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:532:in `try_link0'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:556:in `try_link'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:765:in `try_func'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:997:in `block in have_library'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:942:in `block in checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block (2 levels) in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:350:in `block in postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:320:in `open'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:346:in `postpone'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:941:in `checking_for'
    from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/mkmf.rb:992:in `have_library'
    from extconf.rb:8:in `block in check_libs'
    from extconf.rb:8:in `each'
    from extconf.rb:8:in `all?'
    from extconf.rb:8:in `check_libs'
    from extconf.rb:95:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

/Users/name/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/eventmachine-1.2.7/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/Users/nbame/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/gems/eventmachine-1.2.7 for inspection.
Results logged to
/Users/name/Desktop/GitHub/blog/vendor/bundle/ruby/2.3.0/extensions/universal-darwin-18/2.3.0/eventmachine-1.2.7/gem_make.out

An error occurred while installing eventmachine (1.2.7), and Bundler cannot continue.
Make sure that `gem install eventmachine -v '1.2.7' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  jekyll was resolved to 3.8.3, which depends on
    em-websocket was resolved to 0.5.1, which depends on
      eventmachine

我试过了:

使用 gem install eventmachine -v '1.2.7' --source 'https://rubygems.org/' 这给了我“错误:无法构建 gem 原生扩展。”

brew install coreutils 推荐here

this question的每个回复

关于 Mojave 和 gem 更新失败的答案 here

gem pristine ffi --version 1.9.25 因为它在错误消息中建议这样做

我的 mkmf.log 日志如下

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/universal-darwin18 -I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0 -I. -I/usr/local/opt/openssl/include  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib -L.     -lruby.2.3.0  -lpthread -ldl -lobjc "
In file included from conftest.c:1:
In file included from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
         ^~~~~~~~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: 
5:   return 0;
6: 
/* end */

"pkg-config --exists openssl"
package configuration for openssl is not found

【问题讨论】:

【参考方案1】:

我很幸运地使用 Homebrew 安装了 libffi,然后使用了推荐的构建标志:

$ brew install libffi
==> Downloading https://homebrew.bintray.com/bottles/libffi-3.2.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring libffi-3.2.1.mojave.bottle.tar.gz
==> Caveats
libffi is keg-only, which means it was not symlinked into /usr/local,
because some formulae require a newer version of libffi.

For compilers to find libffi you may need to set:
  export LDFLAGS="-L/usr/local/opt/libffi/lib"

For pkg-config to find libffi you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"
$ LDFLAGS="-L/usr/local/opt/libffi/lib" PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig" bundle install

我有很多使用 FFI 的项目,但我没有导出这些变量(因为它们是全局变量),而是在我的 Bash 配置文件中添加了一个别名,以便我可以轻松地动态设置它们:

# ~/.bash_profile
alias ffi='LDFLAGS="-L/usr/local/opt/libffi/lib" PKG_CONFIG_PATH="/usr/local/opt/libffi/lib/pkgconfig"'

现在每当我有一个使用 FFI 的项目时,我都可以像这样安装 gem:

$ ffi bundle install

【讨论】:

【参考方案2】:

我遇到了同样的问题,也没有任何效果。原来 eventmachine 使用了我的 python 的 anaconda 环境并安装了 openssl。我创建了新的干净 anaconda 环境,然后再次运行 bundle install

【讨论】:

【参考方案3】:

根据错误,“您必须先安装开发工具。”。要安装开发工具,请在终端中运行:

xcode-select --install

Xcode 命令行工具通常需要在主要操作系统更新后重新安装。

【讨论】:

谢谢。我这样做了,并收到“xcode-select:错误:命令行工具已安装,使用“软件更新”安装更新”。然后我使用“softwareupdate --install -a”并重新启动了我的计算机,但不幸的是我的问题仍然存在。

Gem::Installer::ExtensionBuildError: 错误: 无法构建 gem 原生扩展 - Aptana

】Gem::Installer::ExtensionBuildError:错误:无法构建gem原生扩展-Aptana【英文标题】:Gem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension-Aptana【发布时间】:2013-09-2720:30:35【问题描述】:我在进行捆绑安装时收到此错误。我检查了... 查看详情

MySQL 安装:错误:无法构建 gem 原生扩展

】MySQL安装:错误:无法构建gem原生扩展【英文标题】:MySQLInstall:ERROR:Failedtobuildgemnativeextension【发布时间】:2011-01-1104:12:38【问题描述】:我正在尝试将MySQL安装到最新版本,因为某些安装出现问题。我运行命令geminstallmysql并收... 查看详情

therubyracer - Gem::Ext::BuildError: 错误: 无法构建 gem 原生扩展

】therubyracer-Gem::Ext::BuildError:错误:无法构建gem原生扩展【英文标题】:therubyracer-Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension【发布时间】:2014-06-2513:22:42【问题描述】:我正在尝试在Mavericks上安装以下gem版本libv8(3.16.14.3)therubyrac... 查看详情

puma gem - 无法构建 gem 原生扩展

...】:2015-07-2012:17:06【问题描述】:安装pumagem时出现以下错误$宝石安装美洲狮获取:puma-2.11.2.gem(100%)构建原生扩展。这可能需要一段时间...错误:安装puma时出错:错误:无法构建gem原生扩展。红宝石extconf.rb检查-lcrypto中的BI 查看详情

Gem::Ext::BuildError: 错误: 无法构建 gem 原生扩展。 - 塔林杜

】Gem::Ext::BuildError:错误:无法构建gem原生扩展。-塔林杜【英文标题】:Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension.-tharindu【发布时间】:2015-08-1823:35:23【问题描述】:Gem::Ext::BuildError:ERROR:未能构建gem原生扩展。C:/RailsInstaller/Ruby2... 查看详情

安装 pg gem;错误:无法构建 gem 原生扩展

】安装pggem;错误:无法构建gem原生扩展【英文标题】:Installingpggem;ERROR:Failedtobuildgemnativeextension【发布时间】:2013-11-0114:07:33【问题描述】:更新到OSX10.9Mavericks后,我尝试启动Rails3应用程序,但无法连接到PG数据库。检查PGAdminI... 查看详情

Gem::Ext::BuildError: 错误: 无法构建 gem 原生扩展。 - CentOS 6.5

】Gem::Ext::BuildError:错误:无法构建gem原生扩展。-CentOS6.5【英文标题】:Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension.-CentOS6.5【发布时间】:2014-06-1015:06:43【问题描述】:我正在尝试让Ruby版本2.0.0-p353在CentOS6.5上的Nginx1.4.7上运行。... 查看详情

sudo gem install cocoapods 错误:无法构建 gem 原生扩展。?

】sudogeminstallcocoapods错误:无法构建gem原生扩展。?【英文标题】:sudogeminstallcocoapodsERROR:Failedtobuildgemnativeextension.?【发布时间】:2021-01-1223:16:14【问题描述】:Macbigsur,flutterdocker-v[!]Xcode-为iOS和macOS开发(Xcode12.0.1)•Xcode位于/Appli... 查看详情

错误:安装 mysql2 时出错:错误:无法构建 gem 原生扩展

】错误:安装mysql2时出错:错误:无法构建gem原生扩展【英文标题】:ERROR:Errorinstallingmysql2:ERROR:Failedtobuildgemnativeextension【发布时间】:2015-03-0602:17:00【问题描述】:我在尝试为Rails安装geminstallmysql2-v\'0.3.17\'时遇到了一些问题。... 查看详情

错误:安装 ffi 时出错:错误:无法构建 gem 原生扩展

】错误:安装ffi时出错:错误:无法构建gem原生扩展【英文标题】:ERROR:Errorinstallingffi:ERROR:Failedtobuildgemnativeextension【发布时间】:2011-12-1217:54:54【问题描述】:安装了DevKit并重新运行了ffi安装……将其作为输出:C:\\DocumentsandSet... 查看详情

错误:无法构建 gem 原生扩展 - 安装 mysql2 时出错

】错误:无法构建gem原生扩展-安装mysql2时出错【英文标题】:ERROR:Failedtobuildgemnativeextension-Errorinstallingmysql2【发布时间】:2013-11-1422:16:27【问题描述】:运行捆绑安装时出错Installingmysql2(0.3.11)withnativeextensionsGem::Installer::ExtensionBui... 查看详情

使用 gem 安装 cocoapods 时出错

...在使用macOSMojave,当我尝试使用gem安装cocoapods时出现以下错误。构建原生扩展。这可能需要一段时间...错误:错误安装cocoapods:错误:无法构建gem原生扩展。currentdirectory:/Library/Rub 查看详情

无法使用 Mavericks 在我的 Mac 上安装 PG gem

...试安装pggem,以便再次使用我的rails项目。但我得到这个错误:构建原生扩展。这可能需要一段时间...错误:错误安装pg:错误:无法构建gem原生扩展。/Users/jeanosorio/.rvm/rubi 查看详情

ruby nokogiri gem install mac osx high sierra

...y​​进行捆绑安装,但在这个nokogirigem上一直失败。这是错误日志:$sudogem安装nokogiri构建原生扩展。这可能需要一段时间...错误:安装nokogiri时出错:错误:无法构建gem原生扩展。当前目 查看详情

运行 gem install pg -v '0.15.1' 时出错

...2013-05-2304:32:04【问题描述】:跑步geminstallpg-v\'0.15.1\'给出错误:构建原生扩展。这可能需要一段时间...错误:错误安装pg:错误:无法构建gem原生扩展。/home/a 查看详情

gem install pg 在 Mac El Capitan 上不起作用

...题描述】:我尝试在MacElCapitan上安装pgGem,但总是收到此错误:Gem::Installer::ExtensionBuildError:错误:无法构建gem原生扩展。/System/Library/Frameworks/Ru 查看详情

Snow Leopard 上的 Ruby 1.9.2 eventmachine 安装错误

】SnowLeopard上的Ruby1.9.2eventmachine安装错误【英文标题】:Ruby1.9.2eventmachineinstallationerroronSnowLeopard【发布时间】:2012-05-2013:27:18【问题描述】:当我尝试在我的OSX上安装eventmachine时,我收到了这个错误。构建原生扩展。这可能需要... 查看详情

Ubuntu上的sqlite3-ruby安装错误

】Ubuntu上的sqlite3-ruby安装错误【英文标题】:sqlite3-rubyinstallerroronUbuntu【发布时间】:2011-03-2809:07:58【问题描述】:在安装sqlite3-ruby时出现以下错误:构建原生扩展。这可能需要一段时间...错误:安装sqlite3-ruby时出错:错误:无... 查看详情