Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't install libv8 gem on Cygwin

How do I install libv8 gem? I can't install libv8 gem. When I try, I get the below error.

$ 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

I tried to use

$ 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

But bundle install still would not run. It still tried to install version 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 is not in my Gemfile. I don't know how to find out what is trying to use it, but while searching I saw that rubyracer uses libv8 and I do have

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

I even tried to edit the /usr/lib/ruby/gems/1.9.1/gems/libv8-3.11.8.13/src/platform.h file and comment out line 77:

//int random();

But when I ran gem install libv8, it overwrote my changes and still gave an error. I saw a trick in gem install libv8 --help, so I edited the file again and commented out line 77, and tried

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

However, that just gave different errors:

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()’
like image 366
Chloe Avatar asked Feb 12 '13 01:02

Chloe


3 Answers

I feel like there should be an answer for people who just want the error to go away so they can get on with learning rails.

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

like image 133
Jon Carter Avatar answered Sep 30 '22 05:09

Jon Carter


Since your question mentioned Cygwin, I assume you are Windows user. Currently, there's no way to install therubyracer or libv8 in Windows as said by its maintainer: therubyracer gem on windows. Windows is not Rails land unfortunately.

If you do need libv8, you can try nodejs instead. It comes with a binary, handy for all platform.

like image 41
kasperite Avatar answered Sep 30 '22 05:09

kasperite


I've just hit the very same problem on my Win7 dev machine. It looks like installing https://github.com/hiranpeiris/therubyracer_for_windows and adding gem 'therubyracer' to the Gemfile sorts things out.

Before:

$ 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>'
(...)

This basically means that Rails needs rubyracer and therefore libv8.

After:

$ 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]
(...)
like image 31
Jakub Czaplicki Avatar answered Sep 30 '22 04:09

Jakub Czaplicki