"rmagick" gem安装问题

68

我在尝试在CentOS上安装"rmagick" gem时遇到了问题。以下是我遇到的输出。请问有人能帮我确定我缺少哪个软件包吗?我已经按照另一个Stack Overflow线程中提到的所有内容进行了安装:RMagick install error

Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no

Can't install RMagick 2.13.2. Can't find MagickWand.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=/usr/local/bin/ruby


Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2/ext/RMagick/gem_make.out

在按照建议操作后,现在我得到了这个输出结果:

Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... yes
checking for ImageMagick version >= 6.4.9... yes
checking for HDRI disabled version of ImageMagick... 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=/usr/local/bin/ruby
/usr/local/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 /usr/local/lib/ruby/1.9.1/mkmf.rb:506:in `try_cpp'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:931:in `block in have_header'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:790:in `block in checking_for'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:284:in `block (2 levels) in postpone'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:284:in `block in postpone'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:254:in `open'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:280:in `postpone'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:789:in `checking_for'
    from /usr/local/lib/ruby/1.9.1/mkmf.rb:930:in `have_header'
    from extconf.rb:194:in `<main>'


Gem files will remain installed in /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/lib/ruby/gems/1.9.1/gems/rmagick-2.13.2/ext/RMagick/gem_make.out

mkmf.log 的输出结果:

checking for HDRI disabled version of ImageMagick... -------------------- yes

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

"gcc -o conftest -I/usr/local/include/ruby-1.9.1/x86_64-linux -I/usr/local/include/ruby-1.9.1/ruby/backward -I/usr/local/include/ruby-1.9.1 -I.  -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/ImageMagick-6    -fopenmp -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/include/ImageMagick-6   conftest.c  -L. -L/usr/local/lib -Wl,-R/usr/local/lib  -L/usr/lib -lMagickCore-6.Q16      -L/usr/lib -lMagickCore-6.Q16    -Wl,-R -Wl,/usr/local/lib -L/usr/local/lib -lruby-static  -lpthread -lrt -ldl -lcrypt -lm   -lc"
/usr/bin/ld: skipping incompatible /usr/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible /usr/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: skipping incompatible /usr/lib/libMagickCore-6.Q16.so when searching for -lMagickCore-6.Q16
/usr/bin/ld: cannot find -lMagickCore-6.Q16
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"

gem_make.out 的输出与上面终端的输出相同。

8个回答

140

尝试安装

  sudo apt-get install libmagickwand-dev imagemagick

9
看起来很有前途,但只在Ubuntu上有效。 - Sławosz
3
在Ubuntu 12.04上工作过。 - Benjamin Crouzier
11
这是一个安装ImageMagick及其开发库的命令,可以使用yum来安装。具体命令为:yum install ImageMagick-devel ImageMagick - Denys Vitali
1
使用yum在CentOS 7上工作。谢谢。 - Faliorn
1
对于MacOS,请参见我下面的答案。 - Fadils
在Mint 18.2 (Ubuntu 16.04)上工作过。 - Umut ADALI

38

2
如果您正在使用Homebrew并且遇到ImageMagick7的问题,那么这就是正确的答案。 - mindtonic
3
brew link --force imagemagick@6 帮助我安装了 gem dhash。 - Nakilon

18

错误信息显示:

Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found

看起来你根本没有缺少任何包,你只需告诉pkg-config在哪里找到MagickCore.pc文件以构建扩展。如果你使用yum安装了ImageMagick-devel软件包,则该文件应该在目录/usr/lib/pkgconfig/usr/lib64/pkgconfig(取决于你的架构)中。使用以下命令检查一下(从现在开始,我假设你在amd64机器上,如果不是,请用lib替换lib64):

$ find /usr/lib64/pkgconfig -name MagickCore.pc
如果文件已经存在,您只需要使用以下命令安装rmagick:

如果文件存在,则只需使用此命令安装 rmagick :

<code>$ PKG_CONFIG_PATH='/usr/lib64/pkgconfig' gem install rmagick
</code>

谢谢,你的建议很有用。然而,我现在得到了另一个输出(请检查编辑后的问题细节)。我不确定如何处理“由于某些原因(可能是缺少必要的库和/或头文件),无法创建Makefile。请查看mkmf.log文件获取更多详细信息。”。此外,我需要安装输出中提到的开发版本吗? - Rana
嗨,是的,我刚确认已经安装了这个glibc-headers库。还有其他线索吗? - Rana
已在上方添加了mkmf.log文件的输出。请检查是否能找到任何线索。我对这些和Linux都很陌生,所以很迷茫,输出对我来说意义不大:( 。此外,如果您能给我提供一个详细的指南链接,以便我可以从头开始安装RMagick,那将非常有帮助。 - Rana
不,我没有从源代码编译任何软件包。我总是使用“yum install”或“gem install”安装打包的库。这个问题的答案:http://stackoverflow.com/questions/14355798/gem-install-error-with-rmagick?rq=1,你认为这对我也可能是一个类似的情况吗?rmagick与imagemagick版本不兼容? - Rana
1
在Ubuntu 16.04上,现在的路径是PATH="/usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16:$PATH" PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig,可以使用gem install rmagick -v '2.13.2'来安装rmagick。 - werkshy

8
问题是,正如错误提示所说,

在pkg-config搜索路径中未找到MagickCore包

解决方案也在那里:

将包含MagickCore.pc的目录添加到PKG_CONFIG_PATH环境变量中

因此,
  1. Find MagickCore.pc location:

    sudo find / -name MagickCore.pc
    
  2. If it is not found, probably ImageMagick is not installed on your system — then install it (Google how to do it, as it depends on the OS)

  3. Save it to the ENV var like that (make sure to put the path found in step 1):

    PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
    
  4. Retry installing RMagick


2
“directory containing” 的意思是您需要删除文件名才能使其正常工作。因此,PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig - sekrett
当然!谢谢,@sekrett - Sergey Pedan

7
对于使用Brew的Mac电脑,只需执行以下命令:brew install imagemagick。然后gem install imagemagick就可以顺利运行了。

3

看起来你没有缺少任何软件包。错误消息很重要:

也许你应该将包含 `MagickCore.pc' 的目录添加到 PKG_CONFIG_PATH 环境变量中

这个 superuser 重复问题上的几个答案提供了很好的建议。


1
在Debian(不稳定版)中,解决此错误所需的正确软件包是libmagickcore-6.q16-devimagemagicklibmagickwand-6-headers
我通过使用apt-file search MagickCore.pcapt-file search MagickWand.h找到它们。

0

针对遇到此类问题的Windows用户,并且确认已经完全安装了开发工具包:

在安装时,您将看到以下提示 enter image description here

选择1是不够的。只需按Enter键(1和3),即可正确安装开发工具包。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接