2013-03-09 48 views
0

我在Windows上,并从此处下载并安装了rmagick-win32 RMagick-2.12.0-ImageMagick-6.5.6-8-Q8(http://rubyforge.org/frs/?group_id=12&release_id=42049),我将其解压缩并采用“创业板安装rmagick”尝试安装Rmagick后无法运行rails server

当我尝试运行轨道,按装,我得到这个错误信息

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 

所以我尝试捆绑安装或捆绑更新,然后我得到这个(我拿出完整的宝石清单以节省空间):

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. 

然后我下载rmagick 2.13.2,放入同一个文件夹并运行“宝石安装rmagick -v‘2.13.2’,但我得到一个失败的错误:无法建立宝石原生扩展再次

我我试图安装2.13.2,但是我找不到任何有关这方面的信息。任何人都知道如果这是问题,以及如何解决这个问题?

回答

0

在Windows上,您需要使用Ruby的DevKit来编译本机C扩展(包括一些gem)。

1

在Windows上的RMagick是棘手的。当我在Windows上时,我设法找到了两种解决方案来解决过去两年的相同问题。

简便解法

以下添加到您的Gemfile。它也将占其他平台。

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 

然后,使用解压宝石vendors/gems/

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

更好的解决方案

我发现,它有可能在Windows上编译RMagick宝石。遵循此解决方案之前,请确保您已安装DevKit

我创建a batch file说的ImageMagick的目录映射为X:\,并给出参数,在哪里可以找到所需的文件来构建RMagick的gem命令。这种映射是必要的,因为配置选项不知道如何处理路径中的空格。

您可以使用以下命令将ImageMagick的目录映射到X:\并编译并安装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 

如果您安装的版本不是6.7.6-Q16,或者您不在64位Windows上,则需要编辑该路径。

在使用此解决方案安装了gem后,您现在应该能够在Gemfile中将gem 'rmagick', :require => 'RMagick'捆绑在一起。