gem 在 OSX 10.15 上安装 therubyracer -v 0.12.3

Posted

技术标签:

【中文标题】gem 在 OSX 10.15 上安装 therubyracer -v 0.12.3【英文标题】:gem install therubyracer -v 0.12.3 on OSX 10.15 【发布时间】:2020-05-06 19:25:49 【问题描述】:

我已按照步骤安装 v8 和 libv8 gem。之后,我无法成功安装therubyracer 0.12.3。 mkmf.log 在尝试验证 v8.h 标头时阻塞并抛出 unknown type name-error。

我的环境:

红宝石:2.6.3 OSX:10.15 xcode 选择:2373 libv8: 3.16.14.19 v8:v8@3.15(通过 Homebrew) brew info v8@3.15 = v8@3.15: stable 3.15.11.18(瓶装)[仅桶装] g++:Apple clang 版本 11.0.0 (clang-1100.0.33.17)

我已经完成了here 的建议。有人有建议吗?

Gem 安装

gem install therubyracer -v '0.12.3' -- --with-v8-dir=/usr/local/opt/v8@3.15

失败消息

Building native extensions with: '--with-v8-dir=/usr/local/opt/v8@3.15'
This could take a while...
ERROR:  Error installing therubyracer:
ERROR: Failed to build gem native extension.

current directory: /Users/kristinsmith/.gem/ruby/2.6.0/gems/therubyracer-0.12.3/ext/v8
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I 
/Library/Ruby/Site/2.6.0 -r ./siteconf20200120-16109-4pdf22.rb extconf.rb --with-v8- 
dir\=/usr/local/opt/v8@3.15

checking for -lpthread... yes
checking for -lobjc... yes
checking for v8.h... no
*** 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.6/usr/bin/$(RUBY_BASE_NAME)
--with-pthreadlib
--without-pthreadlib
--with-objclib
--without-objclib
--enable-debug
--disable-debug
--with-v8-dir
--with-v8-include
--without-v8-include=$v8-dir/include
--with-v8-lib
--without-v8-lib=$v8-dir/lib
/Users/kristinsmith/.gem/ruby/2.6.0/gems/libv8-3.16.14.19/ext/libv8/location.rb:50:in 
`configure': By using --with-system-v8, you have chosen to use the version  
(Libv8::Location::System::NotFoundError)
of V8 found on your system and *not* the one that is bundled with 
the libv8 rubygem. 

However, your system version of v8 could not be located. 

Please make sure your system version of v8 that is compatible 
with 3.16.14.19 installed. You may need to use the 
--with-v8-dir option if it is installed in a non-standard location
from /Users/kristinsmith/.gem/ruby/2.6.0/gems/libv8-3.16.14.19/lib/libv8.rb:7:in 
`configure_makefile'
from extconf.rb:32:in `<main>'

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

/Users/kristinsmith/.gem/ruby/2.6.0/extensions/universal-darwin-19/2.6.0/therubyracer- 
0.12.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/kristinsmith/.gem/ruby/2.6.0/gems/therubyracer- 
0.12.3 for inspection.
Results logged to /Users/kristinsmith/.gem/ruby/2.6.0/extensions/universal-darwin . 
19/2.6.0/therubyracer-0.12.3/gem_make.out

mkmf.log

...
find_header: checking for v8.h... -------------------- no

"xcrun clang I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10. 
5.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin19 -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/backward -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I. -I/usr/local/opt/v8@3.15/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -Wall -g -rdynamic  -g -Os -pipe -DHAVE_GCC_ATOMIC_BUILTINS  -arch x86_64  -c conftest.c"
clang: warning: argument unused during compilation: '-rdynamic' [-Wunused-command-line-argument]
 In file included from conftest.c:3:
/usr/local/opt/v8@3.15/include/v8.h:98:1: error: unknown type name 'namespace' namespace v8 

 ^
/usr/local/opt/v8@3.15/include/v8.h:98:13: error: expected ';' after top level declarator 
namespace v8 
        ^
        ;
2 errors generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <v8.h>
/* end */

--------------------
...

【问题讨论】:

您可以查看安装的brew info v8 v8 的确切详细信息吗?因为它无法找到checking for v8.h... no 库。 我编辑了帖子以包含酿造信息。 brew info v8@3.15 = v8@3.15:稳定 3.15.11.18(瓶装)[仅限桶装] 您在 mkmf.log 中的错误告诉您编译工具有问题,但是如果 brew 正在运行,这意味着您安装了正确的 xcode 工具,所以我看不出编译器错误是怎么来的.你可以在终端上试试xcode-select -p 1&gt;/dev/null;echo $?,看看return 0是否也很完美,否则你可以试试xcode-select --install 感谢您的提示! xcode-select -p 1&gt;/dev/null;echo $? 返回 0 【参考方案1】:

我遇到了同样的错误,最后似乎 rbenv ruby​​ 版本被忽略了。 运行eval "$(rbenv init -)" 解决了这个问题,并且正确安装了rubyracer。

【讨论】:

【参考方案2】:

非常感谢您的帮助!最终的解决方案竟然是:

    安装rbenv 在 rbenv 中设置 Ruby 版本 (2.6.3) 将以下行添加到我的 .zshrc 中: eval "$(rbenv init -)"(谢谢,Mykolas Kairys) 导出 LDFLAGS="-L~/.rbenv/versions/2.6.3/lib" 导出 CPPFLAGS="-I~/.rbenv/versions/2.6.3/include"

【讨论】:

谢谢!我尝试了所有here,但只有你的解决方案才有效!

以上是关于gem 在 OSX 10.15 上安装 therubyracer -v 0.12.3的主要内容,如果未能解决你的问题,请参考以下文章

在 osx 上安装 pg gem 时出错

使用新的 Ruby 版本在 Mac OSX 上安装 gem

在 OSX 10.11 El Capitan 上安装 therubyracer gem

在 OSX 中卸载所有已安装的 gem?

Bundle 无法在 Mac OSX 10.7 上安装 RMagick gem

ruby nokogiri gem install mac osx high sierra