【问题标题】:Error Installing RMagick for Ruby on Rails on Windows在 Windows 上为 Ruby on Rails 安装 RMagick 时出错
【发布时间】:2015-03-30 17:53:47
【问题描述】:

我正在尝试在我的 Windows 7 上的 Xampp 上安装 Ruby on Rails 和 Redmine。我通过以下链接成功安装了 ImageMagick 和 RMagick:

http://rails.webintellix.com/2010/01/04/how-to-install-rmagick-imagemagick-on-windows/

但是当我运行 bundle install 时出现以下错误:

C:\xampp\htdocs\dev-ruby\redmine>bundle install
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.11
Using multi_json 1.10.1
Using activesupport 3.2.19
Using builder 3.0.4
Using activemodel 3.2.19
Using erubis 2.7.0
Using journey 1.0.4
Using rack 1.4.5
Using rack-cache 1.2
Using rack-test 0.6.2
Using hike 1.2.3
Using tilt 1.4.1
Using sprockets 2.2.3
Using actionpack 3.2.19
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 3.2.19
Using arel 3.0.3
Using tzinfo 0.3.42
Using activerecord 3.2.19
Using activeresource 3.2.19
Using bundler 1.7.6
Using mini_portile 0.6.1
Using nokogiri 1.6.4.1
Using xpath 2.0.0
Using capybara 2.1.0
Using ffi 1.9.6
Using childprocess 0.5.5
Using coderay 1.1.0
Using rack-ssl 1.3.4
Using json 1.8.1
Using rdoc 3.12.2
Using thor 0.19.1
Using railties 3.2.19
Using jquery-rails 3.1.2
Using metaclass 0.0.4
Using mocha 1.0.0
Using mysql 2.8.1
Using net-ldap 0.3.1
Using ruby-openid 2.3.0
Using rack-openid 1.4.2
Using rails 3.2.19
Using rbpdf 1.18.2
Using redcarpet 2.3.0
Using request_store 1.0.5

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
.

    C:/RailsInstaller/Ruby2.0.0/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/Ruby2.0.0/bin/ruby
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler
 failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:562:in `try_cpp'

        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:1041:in `block i
n have_header'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:892:in `block in
 checking_for'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:337:in `block (2
 levels) in postpone'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:337:in `block in
 postpone'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:333:in `postpone
'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:891:in `checking
_for'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:1040:in `have_he
ader'
        from extconf.rb:186:in `<main>'


Gem files will remain installed in C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0
.0/gems/rmagick-2.13.3 for inspection.
Results logged to C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rmagick-2
.13.3/ext/RMagick/gem_make.out
An error occurred while installing rmagick (2.13.3), and Bundler cannot
continue.
Make sure that `gem install rmagick -v '2.13.3'` succeeds before bundling.

所以我尝试使用以下命令安装 rmagick 2.13.3:

gem install rmagick --version=2.13.3 --platform=ruby -- --with-opt-lib=c:/ImageMagick/lib --with-opt-include=c:/ImageMagick/include

但它也给出了这个错误:

C:\Users\user1>gem install rmagick --version=2.13.3 --platform=ruby -- --with-op
t-lib=c:/ImageMagick/lib --with-opt-include=c:/ImageMagick/include
Temporarily enhancing PATH to include DevKit...
Building native extensions with: '--with-opt-lib=c:/ImageMagick/lib --with-opt-i
nclude=c:/ImageMagick/include'
This could take a while...
ERROR:  Error installing rmagick:
        ERROR: Failed to build gem native extension.

    C:/RailsInstaller/Ruby2.0.0/bin/ruby.exe extconf.rb --with-opt-lib=c:/ImageM
agick/lib --with-opt-include=c:/ImageMagick/include
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=${opt-dir}/include
        --with-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=C:/RailsInstaller/Ruby2.0.0/bin/ruby
C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': The compiler
 failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:562:in `try_cpp'

        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:1041:in `block i
n have_header'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:892:in `block in
 checking_for'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:337:in `block (2
 levels) in postpone'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:337:in `block in
 postpone'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:307:in `open'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:333:in `postpone
'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:891:in `checking
_for'
        from C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:1040:in `have_he
ader'
        from extconf.rb:186:in `<main>'


Gem files will remain installed in C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0
.0/gems/rmagick-2.13.3 for inspection.
Results logged to C:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/rmagick-2
.13.3/ext/RMagick/gem_make.out

这是 mkmf.log 文件:

checking for Ruby version >= 1.8.5... -------------------- yes

--------------------

"gcc -o conftest.exe -IC:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/i386-mingw32 -IC:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/backward -IC:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0 -I. -DFD_SETSIZE=2048 -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -g -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -LC:/RailsInstaller/Ruby2.0.0/lib -L.    -lCORE_RL_magick_ -lX11  -lmsvcrt-ruby200  -lshell32 -lws2_32 -limagehlp -lshlwapi  "
In file included from C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby.h:33:0,
                 from conftest.c:1:
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:125:14: error: size of array 'ruby_check_sizeof_voidp' is negative
In file included from C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby.h:33:0,
                 from conftest.c:1:
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h: In function 'rb_float_value':
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:826:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h: In function 'rb_num2char_inline':
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1214:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1214:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1214:35: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1215:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1215:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1215:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h: In function 'rb_class_of':
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1514:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h: In function 'rb_type':
C:/RailsInstaller/Ruby2.0.0/include/ruby-2.0.0/ruby/ruby.h:1531:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
checked program was:
/* begin */
 #include "ruby.h"

 #include <winsock2.h>
 #include <windows.h>
 int main(int argc, char **argv)
 {
   return 0;
 }
/* end */

我该如何解决这个错误?

更新:我也试过这个:

C:\Users\user1>gem install rmagick --version=2.13.3 --platform=ruby -- '--with-o
pt-lib="h:/ImageMagick-6.8.9-Q16/lib" --with-opt-include="h:/ImageMagick-6.8.9-Q
16/include"'

这是结果:

ERROR:  Could not find a valid gem 'rmagick' (= 2.13.3), here is why:
          Unable to download data from https://rubygems.org/ - no such name (htt
ps://rubygems.org/specs.4.8.gz)
ERROR:  Possible alternatives: rmagick

我仍然不知道为什么会出现这些错误!

【问题讨论】:

  • 检查互联网连接,确保您可以下载文件:https://rubygems.org/specs.4.8.gz
  • 我确实有互联网连接,我下载了这个文件。我该怎么办?
  • 你下载了哪个文件?
  • 我按照你的建议下载了 specs.4.8.gz
  • 我建议测试下载文件的能力。现在只需重试安装 rmagick。

标签: ruby-on-rails windows bundler redmine rmagick


【解决方案1】:

请按照以下链接中的步骤操作,您的链接似乎缺少 dll 链接

http://www.redmine.org/projects/redmine/wiki/HowTo_install_rmagick_gem_on_Windows

【讨论】:

  • 我按照所有步骤操作,但仍然出现错误。这太混乱了!!! >set CPATH=C:\ImageMagick\include >set LIBRARY_PATH=C:\ImageMagick\lib >gem install rmagick .....这是错误:
  • C:/RailsInstaller/Ruby2.0.0/lib/ruby/2.0.0/mkmf.rb:431:in `try_do': 编译器无法生成可执行文件。 (RuntimeError) 必须先安装开发工具。
  • 这是我尝试使用 bundle install 时的错误 >bundle install DL is deprecated, please use Fiddle 找不到 Gemfile
  • 您是否从here下载并安装了开发工具
  • 是的,我做到了。我正在关注本教程:nlb-creations.com/2013/06/26/…
【解决方案2】:

这对我有用:

$ gem install rmagick --platform=ruby -- --with-opt-lib=C:/RailsInstaller/ImageMagick-6.7.7-Q8/lib --with-opt-include=c
:/RailsInstaller/ImageMagick-6.7.7-Q8/include 

确保指定您自己的 ImageMagick 版本和安装它的文件路径,并在命令中包含 lib 文件夹

【讨论】: