Thursday, July 31, 2008

在mac上安装RMagick的一个问题及其解决方法

从http://www.imagemagick.org/script/binary-releases.php上下载imagemagick,安装到了/Users/yu/Programs/ImageMagick下,并在~/.profile里设置好以下二个环境变量,在安装过程中extconf.rb会用到,及以后ruby中require "RMagick"会用到。
$> export MAGICK_HOME="/Users/yu/Programs/ImageMagick"
$> export DYLD_LIBRARY_PATH="/Users/yu/Programs/ImageMagick/lib"

然后直接在shell中运行命令:
$> sudo gem install rmagick
碰到以下错误:
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install rmagick --local
checking for Ruby version >= 1.8.2... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.3.0... yes
checking for HDRI disabled version of ImageMagick... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for magick/MagickCore.h... no
Can't install RMagick 2.5.2. Can't find MagickCore.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=/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

在rmagick的安装目录中运行
$> ruby extconf.rb
却是正确的,但sudo则会报错。
只能到Directory Utility中enable root,用root身份来安装。在shell中用root身份进入后再执行最早做的二个export变量的动作,运行:
$> gem install rmagick
Building native extensions. This could take a while...
Successfully installed rmagick-2.5.2
1 gem installed
$> irb -rubygems -r RMagick
>>
成功!
不知道其他用mac的同学安装rmagick2.x版本是否碰到我这个问题,安装RMagick1.x版本跟2.x版本是不一样的。

No comments :