执行某个命令的时候:
...
An error occurred while installing unf_ext (0.0.7.7), and Bundler cannot continue.
Make sure that `gem install unf_ext -v '0.0.7.7' --source 'https://rubygems.org/'` succeeds before bundling.
...
按提示操作:
$ gem install unf_ext -v '0.0.7.7' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR: Error installing unf_ext:
ERROR: Failed to build gem native extension.
current directory: ~/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/gems/unf_ext-0.0.7.7/ext/unf_ext
~/.rbenv/versions/2.7.4/bin/ruby -I ~/.rbenv/versions/2.7.4/lib/ruby/2.7.0 -r ./siteconf20211003-80002-s3hkjk.rb extconf.rb
checking for -lstdc++... *** 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.
...
To see why this extension failed to compile, please check the mkmf.log which can be found here:
~/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-17/2.7.0/unf_ext-0.0.7.7/mkmf.log
...
$ cat ~/.rbenv/versions/2.7.4/lib/ruby/gems/2.7.0/extensions/x86_64-darwin-17/2.7.0/unf_ext-0.0.7.7/mkmf.log
" clang -o conftest -I~/.rbenv/versions/2.7.4/include/ruby-2.7.0/x86_64-darwin17 -I~/.rbenv/versions/2.7.4/include/ruby-2.7.0/ruby/backward -I~/.rbenv/versions/2.7.4/include/ruby-2.7.0 -I. -I~/.rbenv/versions/2.7.4/include -I/usr/local/opt/readline/include -I/usr/local/opt/[email protected]/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -Wno-error=shorten-64-to-32 -fno-common -pipe conftest.c -L. -L~/.rbenv/versions/2.7.4/lib -L. -L~/.rbenv/versions/2.7.4/lib -L/usr/local/opt/readline -L/usr/local/opt/[email protected]/lib -fstack-protector-strong -L/usr/local/opt/readline/lib -L/usr/local/lib -lruby.2.7 "
In file included from conftest.c:1:
In file included from ~/.rbenv/versions/2.7.4/include/ruby-2.7.0/ruby.h:33:
In file included from ~/.rbenv/versions/2.7.4/include/ruby-2.7.0/ruby/ruby.h:29:
~/.rbenv/versions/2.7.4/include/ruby-2.7.0/ruby/defines.h:126:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return !!argv[argc];
6: }
/* end */
头文件找不到很常见,刚开始并未在意。
别人解决这个问题无非是重装 macos sdk / command line tools / xcode,再麻烦一点就是手动设置 CPATH / CFLAGS / CPPFLAGS…,结果到我这里全都无效。
我几乎把谷歌找到的帖子都看了一遍,也没找到一个特例。
最后临时禁了 Nix 才得以解决:
$ sh -c 'export PATH=$(echo $PATH | sed -n "s!$HOME/.nix-profile/bin:!!gp" | sed -n "s!/nix/var/nix/profiles/default/bin:!!gp"); bash'
$$ which clang
/usr/bin/clang
$$ gem install unf_ext -v '0.0.7.7'
Fetching unf_ext-0.0.7.7.gem
Building native extensions. This could take a while...
Successfully installed unf_ext-0.0.7.7
Parsing documentation for unf_ext-0.0.7.7
Installing ri documentation for unf_ext-0.0.7.7
Done installing documentation for unf_ext after 0 seconds
1 gem installed