91

尝试使用“gem install therubyracer -v '0.10.2'”在 Mavericks 上安装 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

谁能帮我弄清楚如何让这个宝石工作?我已经安装了命令行工具。

4

12 回答 12

242

如果您决定使用更新的therubyracergem 版本,您将不再有这个问题

否则:

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
于 2013-11-22T12:48:33.387 回答
16

所以经过一番挣扎后,我终于让它工作了……感谢西蒙和阿尔瓦罗。

不过,我要添加一件事,使用标志 --with-system-v8 对我不起作用......所以我删除了我的系统 v8

brew uninstall v8

和运行

gem install libv8

如果您已经gem install libv8使用系统 v8 标志运行,请务必卸载该 gem 版本(通过运行来完成gem uninstall libv8)。重要的是你不应该使用 brew 提供的那个,它似乎在 Mavericks 中不起作用(它安装得很好,bundler 会报告你的包是完整的,但是当你的应用程序尝试使用 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
于 2013-11-04T06:47:21.163 回答
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 项目的目录。
于 2013-11-03T18:28:49.677 回答
7

我刚刚遇到了同样的问题,目前一种解决方案是使用apple-gcc42而不是clang来编译两个 gem:

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 环境变量,其路径对应于自制软件创建的二进制文件。这肯定是一个更清洁的解决方法。

第三种解决方案是下载 Xcode 4.6.3 并将其安装在Applications文件夹中。然后,在终端输入:

sudo xcode-select --switch /Applications/Xcode4.6.3.app/Contents/Developer
gem install therubyracer

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

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
于 2013-10-28T09:06:19.237 回答
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

于 2013-11-12T13:52:09.133 回答
3

正如许多答案中所建议的那样,最简单的做法是使用 Apple GCC 4.2(而不是随 Xcode 安装的版本)编译 The Ruby Racer 本机扩展。

如果您使用的是 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 安装的版本(Apple LLVM v5 for 10.9 Mavericks/Xcode 5),这个过程 ( ) 就可以工作。

于 2013-11-18T17:33:52.770 回答
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

宝石文件

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

使用bundle而不是gem install therubyracer

于 2013-11-24T10:14:43.633 回答
3

这应该是为遇到问题的任何人安装 therubyracer 的一种安全且干净的方式(无符号链接)。

取自:gem install therubyracer -v 0.11.4 在 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'或您尝试安装的版本。

于 2015-02-03T19:11:53.367 回答
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
于 2016-01-14T08:59:28.803 回答
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
于 2014-04-05T03:22:59.167 回答
0

从 Mavericks 升级到 Yosemite 后,我遇到了这个问题。问题是我用旧版本的 OSX 编译了我的 Ruby 版本。

如果我跑

ruby -rubygems -e 'puts Gem::Platform.new(RUBY_PLATFORM)'

我会得到x86_64-darwin-13而不是x86_64-darwin-14优胜美地。

重新安装 Ruby I

  1. 完全删除旧版本:rvm remove ruby-2.1.1
  2. 从源代码重新安装(--disable-binary 不使用预编译的二进制文件并强制构建):rvm reinstall --disable-binary 2.1

然后,在尝试了上述所有解决方案后,我能够毫无错误地运行bundle install

于 2015-04-30T04:28:21.083 回答
-2

我所做的是对 osx 小牛队:

git clone git@github.com:cowboyd/therubyracer.git

然后:

gem build therubyracer.gemspec
gem install therubyracer-0.12.1.gem

此过程下载并安装了 libv8 的二进制版本。

于 2014-07-22T00:38:19.450 回答