在OSX Mavericks上执行"gem install therubyracer -v '0.10.2'"未安装成功

91

我正在尝试在Mavericks上使用"gem install therubyracer -v '0.10.2'"安装therubyracer,但是遇到以下错误:

/Users/dennischen/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for main() in -lobjc... yes
creating Makefile

make
compiling rr.cpp
clang: warning: argument unused during compilation: '-rdynamic'
rr.cpp:48:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
1 warning generated.
compiling v8.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_array.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_callbacks.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_context.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_date.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_debug.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_exception.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_exception.cpp:10:16: warning: unused variable 'stack' [-Wunused-variable]
  static void* stack[20];
               ^
1 warning generated.
compiling v8_external.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_external.cpp:10:9: warning: unused variable 'references' [-Wunused-variable]
  VALUE references;
        ^
1 warning generated.
compiling v8_function.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_handle.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_locker.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_locker.cpp:45:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
v8_locker.cpp:85:5: warning: control reaches end of non-void function [-Wreturn-type]
    }
    ^
2 warnings generated.
compiling v8_message.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_object.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_object.cpp:77:19: warning: unused variable 'proto' [-Wunused-variable]
    Handle<Value> proto(rr_rb2v8(prototype));
                  ^
1 warning generated.
compiling v8_script.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_string.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_template.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_try_catch.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_v8.cpp
clang: warning: argument unused during compilation: '-rdynamic'
compiling v8_value.cpp
clang: warning: argument unused during compilation: '-rdynamic'
v8_value.cpp:100:9: warning: unused function 'ToInt32' [-Wunused-function]
  VALUE ToInt32(VALUE self) {
        ^
1 warning generated.
compiling v8_weakref.cpp
clang: warning: argument unused during compilation: '-rdynamic'
linking shared-object v8.bundle
clang: error: no such file or directory: '/Users/dennischen/.rvm/gems/ruby-1.9.3-p194@panini/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a'
make: *** [v8.bundle] Error 1

有人可以帮助我弄清楚如何使这个宝石运行吗?我已经安装了命令行工具。


你有安装 homebrew 吗?在安装 gem 之前,尝试使用 brew install v8 安装 v8。 - Ivan Shamatov
我相信brew install v8是一个独立的问题。请参考https://dev59.com/kmgu5IYBdhLWcg3wFDJr了解有关使用brew安装v8的详细信息。 - Ash Blue
12个回答

242
如果您决定使用更新的therubyracer gem版本,则将不再遇到此问题。
否则:
brew tap homebrew/dupes # Thanks Tom
brew install apple-gcc42

export CC=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2
export CXX=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2
export CPP=/usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2

brew uninstall v8

gem uninstall libv8

gem install therubyracer -v '0.10.2' # specify version

11
这种方法似乎比修改符号链接更好。 - Nilesh
3
brew tap homebrew/dupes修复了“Error: No available formula for apple-gcc42”的错误。 - TomFuertes
2
您更新到 therubyracer 0.12.0 后,该问题得到了解决。 - jackocnr
1
对我来说完美地工作了(也使用了 bundle install)。 - Thibaut Barrère
6
很遗憾,在我的OSX 10.9系统上,ruby 2.1.0和therubyracer 0.12.1,这些解决方案都没有起作用。 - turboladen
显示剩余8条评论

16

所以经过一些挣扎,我最终让它工作了...感谢Simon和Alvaro。

不过我有一件事要补充,使用标志--with-system-v8对我没有用...所以我卸载了我的系统v8:

brew uninstall v8

然后运行

gem install libv8

如果您已经使用系统v8标志运行gem install libv8,请确保卸载该gem版本(通过运行gem uninstall libv8来操作)。重要的是您不应该使用由brew提供的那个,因为在Mavericks中似乎无法工作(它安装得很好,bundler会报告您的bundle完成,但当您尝试使用v8时,您的应用程序将失败)。

总结答案,以下操作适用于我:

brew install apple-gcc42
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2 /usr/bin/g++
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2 /usr/bin/cpp

brew uninstall v8
gem install libv8
gem install therubyracer

2
这对我有用。但是我将gcc建立了一个符号链接到/usr/local/bin,并重新启动终端,这样在安装libv8之后就可以将其删除了。 - Jamon Holmgren
2
将Homebrew二进制文件与特定版本链接到/usr/bin中,这是一个非常糟糕的想法。下一个brew update会更新这些路径,导致系统出现故障。 - mrm

10

我也遇到了同样的问题,这个方法对我有用:

使用therubyracer (0.10.2)和libv8 (3.3.10.4)

首先:

  • brew install apple-gcc42
  • 你必须将所有编译器的二进制文件(gcc, cpp, g++)链接到 /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/<compiler>

之后,您可以尝试以下操作:

  • brew install v8
  • gem install libv8 -v '3.3.10.4' -- --with-system-v8
  • gem install therubyracer -v 'therubyracer' 或者 bundle install 到 Rails 项目目录中。

apple-gcc42: 这个配方在 macOS 上要么无法编译,要么不能按预期运行。我的 macOS 是 10.12.6。 - Wylliam Judd

7

我遇到了同样的问题,目前的一个解决方案是使用apple-gcc42代替clang编译这两个gems:

brew install apple-gcc42

然后您可以选择在/usr/bin中为{gcc,g ++,c ++}二进制文件创建一些符号链接:

sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2 /usr/bin/g++
sudo ln -s /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2 /usr/bin/cpp

事实上,g++ 应该足够了。
或者……你可以导出 CC/CXX/CPP 环境变量,并指定路径对应 homebrew 创建的二进制文件。这肯定是一个更干净的解决方法。
第三种解决方案是下载 Xcode 4.6.3 并将其安装在 Applications 文件夹中。然后,在终端中输入:
sudo xcode-select --switch /Applications/Xcode4.6.3.app/Contents/Developer
gem install therubyracer

安装完成后,您可以切换回Xcode 5.0:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

我该如何切换编译器到apple-gcc42? - user2711889
@Simon,当我尝试使用符号链接到编译器时,会出现文件已存在的消息。那是clang文件吗?如果我运行bundle install,它似乎没有使用gcc,因为错误信息中充满了clang引用。 - bonum_cete
如果您正在使用MacPorts,您不必创建符号链接以指向不同的GCC版本,因为该软件自带了一个命令来实现这一点(请参阅我的答案)。 - jshkol

6
我发现了一种解决方法,可以在不安装apple-gcc42的情况下解决问题。
如果您收到的错误信息类似于以下内容,则此方法可行:
clang: error: no such file or directory: '/Users/mscottford/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a'

那么您应该能够完成以下操作:
brew install v8
bundle install 
# after failing create link from brew installed v8 to error location
ln -s /usr/local/Cellar/v8/3.21.17/lib/libv8_base.x64.a /Users/mscottford/.rbenv/versions/1.9.3-p327/lib/ruby/gems/1.9.1/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a
bundle install

来源:https://github.com/cowboyd/therubyracer/issues/277#issuecomment-27734348

这个问题可能是由于您的系统缺少v8的头文件而引起的。您可以通过安装v8-Dev软件包来解决此问题,具体方法如下:
1. 在命令行中输入以下命令:sudo apt-get install v8-dev
2. 安装完成后,请尝试重新运行您的程序。
希望以上信息对您有所帮助!

这个真的很赞!宝石可以在CLI上安装,但RubyMine v6却无法安装...设置这个符号链接最终解决了问题。谢谢! - Ode
1
这是1000%的好消息,感谢@M.ScottFord。我使用rvm,因此我的ln语句是这样的:ln -s /usr/local/Cellar/v8/3.21.17/lib/libv8_base.x64.a ~/.rvm/gems/ruby-1.9.3-p327/gems/libv8-3.3.10.4/lib/libv8/build/v8/libv8.a - Dave Foster

3
如许多答案中所建议的那样,最简单的方法是使用Apple GCC 4.2编译The Ruby Racer本地扩展(而不是使用Xcode安装的版本)。
如果您使用MacPorts,则无需手动设置符号链接来处理GCC二进制文件。 port select命令会为您完成。 如果自从安装Mavericks以来没有更新过MacPorts,请执行sudo port selfupdate。 更新了MacPorts后,请尝试以下操作:
# If you don't have it, install the port for Apple's GCC 4.2
sudo port install apple-gcc42 

    # OR

# If you had apple-gcc42 already (before Mavericks), update it
sudo port upgrade apple-gcc42


# Same result as manual symlinking of GCC in other answers
sudo port select gcc apple-gcc42 && hash -r

# Install therubyracer, will install libv8 gem dependency
#  *note* if you have any existing versions of these gems, remove them
gem install therubyracer

# Restore GCC to system default (optional)
sudo port select gcc none && hash -r

一般来说,这个过程 (sudo port select gcc [version]) 可以在你想要使用特定的 GCC 版本而不是由 Xcode 安装的版本 (对于 10.9 Mavericks/Xcode 5,为 Apple LLVM v5) 的任何时候使用。


1
在Mavericks上对我有用。 - Evo_x

3

我已经成功在ruby 2.0.0p353和os x 10.9上安装了therubyracer 0.12和libv8 3.16.14.3。

安装libv8需要gcc42。

brew install v8
brew install apple-gcc42
sudo ln -sf /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 /usr/bin/gcc
sudo ln -sf /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/g++-4.2 /usr/bin/g++
sudo ln -sf /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/cpp-4.2 /usr/bin/cpp
gem install libv8

therubyracer需要更新的gcc版本

brew install gcc49
sudo ln -sf /usr/local/Cellar/gcc49/4.9-20131110/bin/gcc-4.9 /usr/bin/gcc
sudo ln -sf /usr/local/Cellar/gcc49/4.9-20131110/bin/g++-4.9 /usr/bin/g++
sudo ln -sf /usr/local/Cellar/gcc49/4.9-20131110/bin/cpp-4.9 /usr/bin/cpp

Gemfile
gem 'therubyracer', :require => 'v8', :platforms => :ruby

使用 bundle 替代 gem install therubyracer


谢谢!这终于让我在经过数天的试错后成功通过了bundle install。唯一不同的是,我卸载了由brew安装的所有开发工具,直到gcc --version报告它是苹果LLVM版本并配置了Xcode,然后我将现有的/usr/bin/gcc(等)移出,再将apple-gcc42库建立符号链接,然后我只是复制了原始的gcc、g++和cpp库,而没有安装gcc49(上次我尝试时需要一个小时来配置)。考虑到我尝试了三十多种不同的方法才找到适合我的那个,你的情况可能会有所不同。 - Chris Bloom

3
这应该是一种安全可靠的方法(不使用符号链接)来安装therubyracer,适用于那些遇到问题的人。
从这里获取:gem install therubyracer -v 0.11.4 fails on OS X 10.10 安装Xcode(如果您没有以下版本之一)6.1.1、6.2-beta或6.3-beta,以及(需要)4.6.3
如果您还没有这样做,请执行gem uninstall libv8 切换到Xcode 4.6.3 sudo xcode-select --switch /Applications/Xcode4.6.3.app/Contents/Developer gem install libv8 -v '3.11.8.17' 或与您的therubyracer版本相关的任何版本
切换到Xcode 6.1.1、6.2-beta或6.3-beta(或者如果您想尝试当前的Xcode安装,则调整此行,我已经确认了这3个的工作) sudo xcode-select --switch /Applications/Xcode6.1.1.app/Contents/Developer gem install therubyracer -v '0.11.4' 或您要安装的版本。

1
谢谢@th01,这对我有用...我尝试了我能找到的所有方法三个小时...在我的情况下,是libv8 gem的问题。下载了Xcode4.6.3并使用该版本运行它,成功安装。这里有一个链接,介绍如何安装多个Xcode版本的快速教程:https://blogs.oracle.com/mobile/entry/how_to_install_multiple_xcodes - miligraf
当我下载Xcode 4.6.3并运行sudo xcode-select --switch /Applications/Xcode4.6.3.app/Contents/Developer,然后运行gem install libv8 -v '3.3.10.4'时,我收到以下错误提示:unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!我做错了什么? - Wylliam Judd

1

当我尝试安装therubyracer 0.12.0以使其与libv8配合使用时,遇到了几乎相同的错误。这对我有用:

$ brew upgrade gcc

$ gem uninstall therubyracer

$ gem uninstall libv8

$ gem install therubyracer -v '0.12.0'
Fetching: therubyracer-0.12.0.gem (100%)
Building native extensions.  This could take a while...
Successfully installed therubyracer-0.12.0
1 gem installed

$ gem install libv8 -v '3.16.14.3' -- --with-system-v8
Fetching: libv8-3.16.14.3.gem (100%)
Building native extensions with: '--with-system-v8'
This could take a while...
Successfully installed libv8-3.16.14.3
1 gem installed

0

当我从OSX Mountain Lion升级到OSX Mavericks时,我遇到了同样的问题。

将ruby-1.8.7-p354升级到ruby-1.8.7-375对我有用。

也许尝试将ruby 1.9.3-p194升级到rc1(1.9.3现在已经超过p484)

假设您使用rbenv:

rbenv install 1.9.3-rc1
rbenv rehash
rbenv global 1.9.3-rc1
bundle install

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接