我将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
上。
希望有人可以提供帮助。
答案 0 :(得分:0)
我必须运行以下加密命令才能安装nokogiri。基本上,这需要使我的C编译器在Mac OS X Mojave中工作,并且在以前的操作系统中一切正常之后(Yosemite,我认为它是...)
这是升级osx时的(某种程度上)明显的步骤:
xcode-select --install
我还必须这样做,如果没有google和this post
,我将永远不知道该怎么做。sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
最后,我必须同意xcode许可证(发现当nokogiri安装失败时,我必须通过makefile日志来执行此操作...)
sudo xcodebuild -licence
它会提示您最终输入“同意”
最后,继续进行bundle
可以对包含nokogiri的新Rails项目按预期进行。成功!