What is Rubygem's equivalent of the '-I' flag? - ruby

When I build a project with gcc, I can use the very useful -I flag to specify additional include dirs. Sometimes, gems require code to be compiled, but I can't use the -I flag. Specifically, I can't build RMagick on my machine because it fails on the MagickWand step:
checking for wand/MagickWand.h... no
I know exactly where MagickWand.h is. How do I tell gem where to find it?
UPDATE:
I have two versions of ImageMagick on my system (for work) and gem throws this error:
Warning: Found more than one ImageMagick installation. This could cause problems at runtime.
/a/Magick-config reports version 6.5.8 Q8 is installed in [a]
/b/Magick-config reports version 6.6.4 Q16 is installed in [b]
Using 6.5.8 Q8 from [a].
gem is using version [a] whereas I want it to use version [b]...but I can't find any way to have it switch to [b]. As far as I can tell, gem doesn't consult my $PATH.

The guides indicate that like you can pass build options
If an extension fails to compile during gem installation the gem specification is not written out, but the gem remains unpacked in the repository. You may need to specify the path to the library’s headers and libraries to continue. You can do this by adding a – between RubyGems’ options and the extension’s build options:
$ gem install some_extension_gem
[build fails]
Gem files will remain installed in /path/to/gems/some_extension_gem-1.0 for inspection.
Results logged to /path/to/gems/some_extension_gem-1.0/gem_make.out
$ gem install some_extension_gem -- --with-extension-lib=/path/to/lib
[build succeeds]
$ gem list some_extension_gem
*** LOCAL GEMS ***
some_extension_gem (1.0)
$
For you, that sounds like gem install rmagick -- -I /path/to/MagickWand.h but I'm not really sure how to try it out to verify.

Related

Error installing debug_inspector 0.0.2 Native Extensions?

Getting this error when trying to do a bundle install. Following the instructions to do a direct gem install fails as well. I have since wiped all ruby (and project code) from my machine including any ruby configuration and reinstalled ruby, devkit, and my project code. Still getting this. Not sure where to look next. Most searches turn up gem-specific solutions that don't seem to apply here. Let me know if I can provide more info. Thanks!
An error occurred while installing debug_inspector (0.0.2), and Bundler cannot
continue.
Make sure that `gem install debug_inspector -v '0.0.2'` succeeds before
bundling.
C:\TFS\Grange Commercial SEQ\White\Specifications>gem install debug_inspector -v
'0.0.2'
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
The system cannot find the path specified.
The system cannot find the path specified.
ERROR: Error installing debug_inspector:
ERROR: Failed to build gem native extension.
C:/devl/Ruby/Ruby192/bin/ruby.exe extconf.rb
Gem files will remain installed in C:/devl/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems
/debug_inspector-0.0.2 for inspection.
Results logged to C:/devl/Ruby/Ruby192/lib/ruby/gems/1.9.1/gems/debug_inspector-
0.0.2/ext/debug_inspector/gem_make.out
I know this question is very old. However, I see two problems with this right off.
Windows doesn't have the tools (by default, or using the ruby installer) to compile c dependencies for ruby. If you want to do it yourself, you might check out: http://rubylearning.com/blog/how-do-i-install-a-ruby-gem-with-native-extensions-on-windows/
The other problem is that this particular gem doesn't work with ruby < 2.0: https://github.com/banister/debug_inspector and your ruby version appears to be 1.9.1
I would check your Gemfile.lock to see which gems are requiring debug-inspector. If you can do without them, take them out, and your bundle will succeed. If you must have them, try running a linux VM and using it for your development. My personal suggestion would be Ubuntu: http://www.ubuntu.com/download/desktop and VirtualBox or VMWare Player. Virtual Box is FOSS, so if this is company work, you'll have to use it: https://www.virtualbox.org/ . VMWare Player is free for personal use, and I like how it works a little better: http://www.vmware.com/products/player
I got the same error, using Ruby 2.2.4 64bit, on windows 10 64.
In my case what caused the error was installing several ruby versions, one after the other- (to try and solve that error)
Eventually I solved it by running ruby dk.rb install --force (At first I did that without the force flag), as stated by this answer- Just make sure to use the correct ruby version- version that worked for me was ruby 2.1.7 32bit.

Copy compiled gem to other computer, avoiding compiling again

Using RVM, how can I copy gems between two different computers? The gem is compiled and I want to avoid a compilation on the target machine.
I tried to copy the .rvm/gems/ruby-x.x.x-pxxx#gemset/gems/gem_name directory, and also the /bin and /cache, but in the target computer I can't see the gem in the gem list output.
Is there anything else I need to do?
You have to copy also the gem specification file you find in .rvm/gems/ruby-x.x.x-pxxx#gemset/specifications/gem_name.gemspec.
Keep in mind that the binary code could not run on the destination platform.
You could use gem-compiler from Luis Lavena.
It should be as easy as (replace <gem-*> with actual gem information):
gem install gem-compiler
gem fetch <gem-name> --platform=ruby
gem compile <gem-name>-<gem-version>.gem
This commands will create the *.gem file for your platform which can be then moved to another machine and installed with gem install --local <gem-file>.
For more details check https://github.com/luislavena/gem-compiler#usage

JRuby: Nokogiri 1.6 Failing To Install & Bundler Attempting To Install Already Met Dependency

I am getting an error on jruby (linux) when installing the
"trinidad_diagnostics_extension" gem (though this question is not about trinidad). A chain of dependencies is
generating the error:
"trinidad_diagnostics_extension" depends on "jruby-lint >= 0.3.0"
"jruby-lint >= 0.3.0" in turn depends on "nokogiri >= 1.5.0.beta.4"
Before attempting to install "trinidad_diagnostics_extension", the relevant
part of my gem list looks like this:
$gem list
nokogiri (1.5.9 java)
jruby-lint (0.4.1)
As you can see, the needed dependencies seem already to be met. Nonetheless,
after adding gem 'trinidad_diagnostics_extension' to my Gemfile and then
running jruby -S bundle install, the bundler attempts to install nokogiri
(1.6.0.rc1), and during this installation fails with the following error:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
... bunch of omitted output here
nokogiri.c:42:18: fatal error: util.h: No such file or directory
compilation terminated.
make: *** [nokogiri.o] Error 1
Gem files will remain installed in /home/jg/.rvm/gems/jruby-1.7.3/gems/nokogiri-1.6.0.rc1 for inspection.
Results logged to /home/jg/.rvm/gems/jruby-1.7.3/gems/nokogiri-1.6.0.rc1/ext/nokogiri/gem_make.out
Why is bundler trying to install nokogiri when that dependency is already met?
How can I fix this? Successfully installing nokogiri 1.6 or making the trinidad extension aware that 1.6 does not need to be installed would both be fine solutions.
In case it's relevant I have JRUBY_OPTS=-Xcext.enabled=true
UPDATE
I was able to get it work by first installing the gem outside of bundler:
jruby -S gem install trinidad_diagnostics_extension
And then the bundle command worked fine, since it was already installed. So I got it working by I am still confused by why I had to install it outside of bundler and why that would matter, and would like some insight if anyone has it.
1.6.0.pre1 does not exist for the Java platform, for uninteresting reasons. That said, you should only get prereleases if you specifically ask for them.

hubris fails to install with: Missing C libraries: ruby, ruby, ruby

I am desperately trying to install Hubris but the installation fails whenever I run "cabal install".
Link to Hurbis:
https://github.com/mwotton/Hubris/tree/master/Haskell
Link to the Cabal file:
https://github.com/mwotton/Hubris/blob/master/Haskell/hubris.cabal
The cabal command that fails is:
cabal install --extra-include-dirs=/usr/include/ruby-1.9.1/x86_64-linux --extra-include-dirs=/usr/include/ruby-1.9.1 --extra-lib-dirs=/usr/lib --user --enable-shared --with-ghc=/usr/local/bin/ghc
The error message is:
Resolving dependencies...
Configuring hubris-0.0.4...
cabal: Missing dependencies on foreign libraries:
* Missing C libraries: ruby, ruby, ruby
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
cabal: Error: some packages failed to install:
hubris-0.0.4 failed during the configure step. The exception was:
ExitFailure 1
THE RAKE ERROR IS THE SAME:
+install -c tmp/x86_64-linux/stub/1.9.3/stub.so lib/stub.so
cabal: Missing dependencies on foreign libraries:
* Missing C libraries: ruby, ruby, ruby
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.
cabal: Error: some packages failed to install:
hubris-0.0.4 failed during the configure step. The exception was:
ExitFailure 1
rake aborted!
ERROR: ran cabal update; cd Haskell; cabal install --extra-include-
dirs=/usr/include/ruby-1.9.1/x86_64-linux --extra-include-dirs=/usr/include/ruby-1.9.1 -
-extra-lib-dirs=/usr/lib --user --enable-shared --with-ghc=/usr/local/bin/ghc, got
Downloading the latest package list from hackage.haskell.org
I also installed 'ruby-dev', e.g.
apt-get install ruby1.9.1-dev
Probably the error is related to missing header files and wrong include directories when I run the cabal command.
.
System Configuration:
ubuntu 12.04
GHC version 7.4.1
ruby version 1.9.3p0
gem version 1.8.24
You should install Hubris using rake. Simply invoking rake in the root of the repository should work. The task that builds the library will find the relevant ruby include directories for you.
I had to make some changes to make the compile work with modern Haskell (E.g. Haskell Platform 2012.2.0.0). The changes are available at https://github.com/dflemstr/Hubris.
It works for me on Arch Linux:
Arch ... well it's rolling release, so there is no version number
GHC version 7.4.2
ruby version 1.9.3p194 (2012-04-20 revision 35410)
gem version 1.8.23
FINAL ANSWER!!! EVERYTHING WORKS!!!
The credit for the right answer goes to User 'dflemstr'. BUT look at this answer for some details, especially for Ubuntu Users. Credit also goes to Mark Wotton, as the install errors where mainly due to Haskell/Cabal and Ubuntu.
_
Requirements:
(tested with this setup, other version probably work too)
Ubuntu 12.04 (Arch Linux works too)
Ruby 1.9.3p0
GHC 7.4.1
Haskell Platform 2012.2.0.0
_
Ruby Installation
sudo apt-get install libruby1.9.1 libruby1.9.1-dbg libtcltk-ruby1.9.1 ruby1.9.1 ruby1.9.1-dev ruby1.9.1-examples ruby1.9.1-full rubybook rubygems
_
Gem Update System (optional)
sudo env REALLY_GEM_UPDATE_SYSTEM=1 gem update --system
_
Fix for Ubuntu
(error Missing C libraries: ruby, ruby, ruby)
cd /usr/lib
ln -s libruby-1.9.1.so ./libruby.so
_
GHC Installation
NOTE: I don't use any ubuntu packages for GHC and the haskell platform. Some people on stackoverflow recommend this.
http://www.haskell.org/ghc/download_ghc_7_4_1
(follow the instructions on the website)
_
Haskel Platform Installation
http://lambda.haskell.org/platform/download/2012.2.0.0/haskell-platform-2012.2.0.0.tar.gz
(again follow the instructions on the website)
.
_
Enable shared library support for haskell packages
Add the following line: "shared: True"
nano ~/.cabal/config
_
Reinstall every haskell package with shared support
Follow the instructions given in:
Building a haskell interpreter (hint) as dynamic library, useable from C++: Missing Interpreter.dyn_hi
Cabal rebuild all with enable-shared flag
NOTE: The above instructions did not work for me!!
In that case, manually reinstall every package by hand (!) with force:
cabal install hint-0.3.3.4 --reinstall --force-reinstall
Repeat with every installed package! e.g. also the mtl package, etc. You may get the same error with a package that is needed for the reinstallation. Just reinstall that package and any recursive dependencies.
If you install Hubris right away, i.e. skipping this step, you get the following error (only in ubuntu, not arch linux):
Language/Ruby/Hubris/LibraryBuilder.hs:13:8:
Could not find module `Control.Monad.Error.Class'
Perhaps you haven't installed the "dyn" libraries for package `mtl-2.0.1.0'?
Use -v to see a list of the files searched for.
cabal: Error: some packages failed to install:
Install needed haskell packages
cabal install c2hs
Install needed ruby packages
sudo gem install rake open4 rspec hoe
sudo gem install bundler
sudo gem install rake-compiler
sudo gem install rspec
Get Hurbis via github
git clone https://github.com/dflemstr/Hubris.git
(Note: This is just for now. As the changes are merged, the original github version from Mark Wotton should be pulled!)
Fix Rakefile to find GHC in ubuntu
Change "/usr/bin/ghc" to "/usr/local/bin/ghc":
cd Hubris
nano Rakefile
Run rake
cd Hubris
rake
If you get errors like "Perhaps you haven't installed the 'dyn' libraries for" here it is possibly due that some package are not reinstalled (see step: 'Reinstall every haskell package with shared support').
**Install Hubris*
cd Hubris
sudo rake install
Install rake
Fix permissions:
chmod -R 777 /var/hubris
NOTE: Don't use 777!! If you do, change later to 755 or 766, etc. This is just for testing!
This is needed because rake install is done with 'sudo' but the cabal packages are installed with a different user. Hubris compiles the haskell files in /var/hubris/ which is not accessible for a regular user unless you change the permissions.
Run test example
Add the following lines to "test.rb":
require 'hubris' # best line ever
class Target
hubris :inline =>"triple::Int->Int; triple n = 10*n"
end
t = Target.new
puts t.triple(3)
Execute test.rb:
ruby test.rb
Check if the result is okay:
The last three lines of the console output should be:
... many lines and possibly GHC error messages ...
|
error ||
30
If the last line is "30" then everything works!! Note that when you run the command a second time the inline haskell is not recompiled, therefore the output is much shorter, but the last line is still "30".
Final Words
Thanks to Mark Wotton for providing Hubris!! It is an excellent starting point to add new features to the library. Great that it is open source!

Cannot install RCov from Gem

gem install rcov
Error:
Building native extensions. This could take a while...
ERROR: Error installing rcov:
ERROR: Failed to build gem native extension.
"C:/Program Files/Ruby191/bin/ruby.exe" extconf.rb
creating Makefile
make
Makefile:154: warning: overriding commands for target `C:/Program'
Makefile:148: warning: ignoring old commands for target `C:/Program'
make: *** No rule to make target `"/C/Program', needed by `callsite.o'. Stop.
Gem files will remain installed in C:/Program Files/Ruby191/lib/ruby/gems/1.9.1/gems/rcov-0.9.8 for inspection.
Results logged to C:/Program Files/Ruby191/lib/ruby/gems/1.9.1/gems/rcov-0.9.8/ext/rcovrt/gem_make.out
This output is now after installing DevKit - to the root Ruby folder.
Indeed, Gem is trying to compile the software for your OS (Windows, apparently).
If you are using the RubyInstaller (rather than the incomplete packages at http://ruby-lang.org), you should add the DevKit and you will get tools like make, gcc, etc. that will be able to compile many of the gems natively.
Otherwise, you should be able to use the Win32 binary version of the Rcov gem.
Sadly, the DevKit can't always compile every gem on Win32. But first, a question: did you follow Step 2 of the DevKit's installation instructions to edit the fstab file? If so, then the next best thing to do is email the RubyInstaller Google Group with details of the compilation problem.
I just tried the Win32 binary rcovrt.so from the Rcov site on my own Windows box, but it doesn't recognize as a valid Windows image, at least with my Ruby 1.9 installation... so figuring out how to make the DevKit compilation to work may be your best bet.
The gem you're trying to use needs to compile native extensions (code which is compiled per system), and for that, it's using a makefile. Have you tried installing make?
You are correct, it is using GNU make. One option is to install cygwin and install make (under the devel tree in cygwin setup).

Resources