0
votes

I'm on windows and I downloaded and installed rmagick-win32 RMagick-2.12.0-ImageMagick-6.5.6-8-Q8 from here (http://rubyforge.org/frs/?group_id=12&release_id=42049) which I unzipped and installed using 'gem install rmagick'

When I try to run rails s, I get this error message

C:\Users\Me\Desktop\sample_app>rails s
←[31mCould not find gem 'rmagick (>= 0) x86-mingw32' in any of the gem sources l
isted in your Gemfile.←[0m
←[33mRun `bundle install` to install missing gems.←[0m

So I try to bundle install or bundle update then I get this (I took out the full list of gems to save space):

C:\Users\Me\Desktop\sample_app>bundle update

Fetching source index for https://rubygems.org/
Installing rmagick (2.13.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.

        C:/RailsInstaller/Ruby1.9.3/bin/ruby.exe extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for stdint.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby1.9.3/bin/ruby
C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:381:in `try_do': The compiler
 failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'

        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:931:in `block in
 have_header'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:790:in `block in
 checking_for'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:284:in `block (2
 levels) in postpone'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:254:in `open'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:284:in `block in
 postpone'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:254:in `open'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:280:in `postpone
'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:789:in `checking
_for'
        from C:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/mkmf.rb:930:in `have_hea
der'
        from extconf.rb:194:in `<main>'


Gem files will remain installed in C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9
.1/gems/rmagick-2.13.2 for inspection.
Results logged to C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rmagick-2
.13.2/ext/RMagick/gem_make.out
An error occured while installing rmagick (2.13.2), and Bundler cannot continue.

Make sure that `gem install rmagick -v '2.13.2'` succeeds before bundling.

Then I downloaded rmagick 2.13.2 and put it into the same folder and ran "gem install rmagick -v '2.13.2' but I'm getting a failed ERROR: Failed to build gem native extension again

I am trying to get 2.13.2 installed but I can't find any information on this. Anyone know if that's the issue and how this can be fixed?

2

2 Answers

1
votes

RMagick on Windows is tricky. I managed to find two solutions to solve the same problem over the last two years back when I was on Windows.

The Simple Solution

Add the following to your Gemfile. It will also account for other platforms.

if RUBY_PLATFORM =~ /(win|w)32$/
  gem 'rmagick', '2.12.0', :path => 'vendor/gems/rmagick-2.12.0-x86-mswin32', :require => 'RMagick'
else
  gem 'rmagick', :require => 'RMagick'
end

Then, unpack the gem to vendors/gems/ using:

gem unpack rmagick-2.12.0-x86-mswin32.gem vendors/gems/

A Better Solution

I found that it is possible to compile the RMagick gem on Windows. Ensure that you have DevKit installed before following this solution.

I have created a batch file that maps the directory of ImageMagick to X:\ and gives parameters to the gem command on where to find the required files to build RMagick. This sort of mapping is necessary as the configuration options don't know how to handle spaces in the paths.

You can use the following commands to map the directory of ImageMagick to X:\ and compile and install the gem.

subst X: "C:\Program Files (x86)\ImageMagick-6.7.6-Q16"
gem install rmagick --platform=ruby -- --with-opt-lib="X:\lib" --with-opt-include="X:\include"
subst X: /D

You will need to edit the path if you have a version other than 6.7.6-Q16 installed or if you are not on 64-bit Windows.

After the gem has been installed with this solution, you should now be able to bundle with just gem 'rmagick', :require => 'RMagick' in your Gemfile.

0
votes

On Windows, you need the DevKit for Ruby to compile native C extensions (which some gems have included).