gpt4 book ai didi

ruby - 无法安装 gem - extconf.rb 失败

转载 作者:行者123 更新时间:2023-12-05 07:27:54 26 4
gpt4 key购买 nike

我将 macos 升级到 Mojave 并重新安装了 xcode、xcode CLT、ruby 等。然后当我尝试时:

gem install nokogiri

我收到以下错误(安装其他 gem 时出现类似错误):

ERROR: Failed to build gem native extension.

current directory: /usr/local/lib/ruby/gems/2.5.0/gems/nokogiri-1.8.5/ext/nokogiri
/usr/local/opt/ruby/bin/ruby -r ./siteconf20181209-20884-etfc5r.rb extconf.rb
checking if the C compiler accepts ... *** 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.

我检查了 mkmf.log,其中包含以下内容:

"clang -o conftest -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/x86_64-darwin18 -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby/backward -I/usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0 -I.  -I/usr/local/opt/libyaml/include -I/usr/local/opt/openssl/include -I/usr/local/opt/readline/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -O3 -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wshorten-64-to-32 -Wimplicit-function-declaration -Wdivision-by-zero -Wdeprecated-declarations -Wextra-tokens  -fno-common -pipe conftest.c  -L. -L/usr/local/Cellar/ruby/2.5.3_1/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib     -lruby.2.5.3  -lpthread -ldl -lobjc "
In file included from conftest.c:1:
In file included from /usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby.h:33:
In file included from /usr/local/Cellar/ruby/2.5.3_1/include/ruby-2.5.0/ruby/ruby.h:29:

文字就这样持续了一会儿。我也cd到nokogiri文件夹,直接运行extconf.rb,出现如下错误:

checking if the C compiler accepts ... *** 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
--with-opt-include

...(为简洁起见跳过类似内容,继续往下看)

usr/local/Cellar/ruby/2.5.3_1/lib/ruby/2.5.0/mkmf.rb:456:in 'try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

我尝试安装 xcode。我还安装了标题并确认了许可证。起初我以为它与 GCC 有关,但 mkmf 文件显示问题出在 Clang

希望有人能帮忙。

最佳答案

我必须运行以下神秘命令才能安装 nokogiri。基本上这需要让我的 C 编译器在 mac osx Mojave 中工作,在之前的操作系统中一切正常(我认为是优胜美地...)

这是升级 osx 时一个(有点)显而易见的步骤:

xcode-select --install

我也必须这样做,如果没有谷歌和 this post,我永远不知道该怎么做

sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

最后,我不得不同意 xcode 许可证(发现我必须在安装 nokogiri 失败时通过 makefile 日志来执行此操作...)

sudo xcodebuild -licence

它会提示你最终输入“同意”

最后,对于包含 nokogiri 的新 Rails 项目,继续使用 bundle 可以正常工作。成功!

关于ruby - 无法安装 gem - extconf.rb 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53700851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com