我将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上。
希望有人能帮上忙。
发布于 2019-02-08 22:47:50
我不得不运行以下神秘的命令来安装nokogiri。基本上,这需要让我的C编译器在mac osx Mojave上运行,在之前的OS (Yosemite,我认为它是...)上一切都运行得很好。
在升级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它会提示你最终输入"agree“
最后,在包含nokogiri的新rails项目中继续使用bundle。成功!
https://stackoverflow.com/questions/53700851
复制相似问题