6

如何安装 libv8 gem?我无法安装 libv8 gem。当我尝试时,我收到以下错误。

$ gem install libv8
Building native extensions.  This could take a while...
ERROR:  Error installing libv8:
        ERROR: Failed to build gem native extension.

        /usr/bin/ruby.exe extconf.rb
creating Makefile
Using compiler: /usr/bin/g++
which: no gmake in (/usr/local/bin:/usr/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS:/cygdrive/c/WINDOWS/System32/Wbem:/cygdrive/c/WINDOWS/system32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn/VSShell/Common7/IDE:/cygdrive/c/Program Files/Microsoft SQL Server/100/Tools/Binn:/cygdrive/c/Program Files/Microsoft SQL Server/100/DTS/Binn:/cygdrive/c/Program Files/Heroku/bin:/cygdrive/c/Program Files/ruby-1.9.2/bin:/cygdrive/c/Program Files/git/bin:/cygdrive/c/Program Files/git/cmd:/cygdrive/c/Program Files/DTN/IQFeed:/cygdrive/c/Program Files/OpenVPN/bin:/cygdrive/c/Program Files/Java/apache-ant-1.8.3/bin:/usr/lib/lapack:/cygdrive/c/Program Files/Notepad++:.:/cygdrive/c/Program Files/Java/android-sdk/platform-tools/:/cygdrive/c/Program Files/Java/android-sdk/tools/:/cygdrive/c/Program Files/Java/jdk1.7.0_03/bin)
In file included from ../src/conversions-inl.h:42:0,
                 from ../src/conversions.cc:32:
../src/platform.h:77:12: error: new declaration ‘int random()’
/usr/include/cygwin/stdlib.h:29:6: error: ambiguates old declaration ‘long int random()’
make[1]: *** [/usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/vendor/v8/out/ia32.release/obj.target/preparser_lib/src/conversions.o] Error 1

我试着用

$ gem install libv8 --pre
Fetching: libv8-3.5.10.beta1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed libv8-3.5.10.beta1
1 gem installed

bundle install还是不会跑。它仍然尝试安装版本 3.11.8.13。

Installing libv8 (3.11.8.13) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

libv8 gem 不在我的 Gemfile 中。我不知道如何找出试图使用它的东西,但是在搜索时我看到 ruby​​racer 使用 libv8,我确实有

group :assets do
  gem 'therubyracer', :platform => :ruby

我什至尝试编辑/usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/src/platform.h文件并注释掉第 77 行:

//int random();

但是当我运行时gem install libv8,它覆盖了我的更改并且仍然给出了错误。我在 中看到了一个技巧gem install libv8 --help,所以我再次编辑了文件并注释掉了第 77 行,并尝试了

cd /usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/vendor/v8
make

但是,这只是给出了不同的错误:

In file included from /usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/winsock2.h:56:0,
                 from ../src/win32-headers.h:77,
                 from ../src/platform-win32.cc:31:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/psdk_inc/_fd_types.h:100:2: warning: #warning "fd_set and associated macros have been defined in sys/types.      This can cause runtime problems with W32 sockets"
In file included from ../src/win32-headers.h:80:0,
                 from ../src/platform-win32.cc:31:
/usr/lib/gcc/i686-pc-cygwin/4.5.3/../../../../include/w32api/wspiapi.h:26:41: error: expected ‘>’ before numeric constant
../src/platform-win32.cc: In function ‘int random()’:
../src/platform-win32.cc:122:12: error: new declaration ‘int random()’
/usr/include/cygwin/stdlib.h:29:6: error: ambiguates old declaration ‘long int random()’
4

3 回答 3

4

我觉得应该为那些只想让错误消失的人找到一个答案,这样他们就可以继续学习。

It seems that you don't need 'therubyracer' specifically -- you can choose some other javascript engine.

Specifically, open the file Gemfile, and change 'therubyracer' to 'therubyrhino'. (If rhino doesn't work, there are more options and advice at: https://github.com/sstephenson/execjs#readme

于 2013-07-19T13:48:57.140 回答
1

由于您的问题提到了 Cygwin,我假设您是 Windows 用户。目前,没有办法在 Windows 中安装 therubyracer 或 libv8,正如其维护者所说:therubyracer gem on windows。不幸的是,Windows 不是 Rails 领域。

如果你确实需要 libv8,你可以试试 nodejs。它带有一个二进制文件,适用于所有平台。

于 2013-02-12T03:06:03.053 回答
1

我刚刚在我的 Win7 开发机器上遇到了同样的问题。它看起来像安装https://github.com/hiranpeiris/therubyracer_for_windows并添加gem 'therubyracer'Gemfile排序的东西。

前:

$ rails generate
c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)
    from c:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:in `<module:ExecJS>'
(...)

这基本上意味着 Rails 需要rubyracer,因此libv8.

后:

$ rails generate
    SECURITY WARNING: No secret option provided to Rack::Session::Cookie.
    This poses a security threat. It is strongly recommended that you
    provide a secret to prevent exploits that may be possible from crafted
    cookies. This will not be supported in future versions of Rack, and
    future versions will even invalidate your existing user cookies.

    Called from: c:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/session/abstract_store.rb:28:in `initialize'.

Usage: rails generate GENERATOR [args] [options]
(...)
于 2013-02-22T13:31:28.700 回答