如何安装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中。我不知道如何找出试图使用它的内容,但在搜索时我发现rubyracer使用的是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()’
答案 0 :(得分:4)
对于那些只想让错误消失的人,我觉得应该有一个答案,这样他们就可以继续学习。
您似乎不需要'therubyracer'专门 - 您可以选择其他一些javascript引擎。
具体来说,打开文件Gemfile
,将'therubyracer'更改为'therubyrhino'。 (如果rhino不起作用,则有更多选项和建议:https://github.com/sstephenson/execjs#readme
答案 1 :(得分:1)
由于您的问题提到了Cygwin,我假设您是Windows用户。目前,没有办法在Windows中安装therubyracer或libv8,如其维护者所说:therubyracer gem on windows。不幸的是,Windows不是Rails。
如果你确实需要libv8,你可以尝试使用nodejs。它带有一个二进制,方便所有平台。
答案 2 :(得分: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]
(...)