在新的RHEL6服务器上安装ruby-filemagic gem遇到了困难。

14

看起来它正在寻找libmagic.so.1文件。我有这个文件。它位于/usr/lib64。我没有使用root用户运行此安装。

我还在使用rvm和Bundler。当我的Gemfile中的ruby-filemagic行到达时,这是我“bundle”命令的结果:

[server@mine ext]$ ruby extconf.rb --with-magiclib
checking for magic_open() in -ltrue... no
*** ERROR: missing required library to compile this module
*** 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.

更新:

以下是mkmf.log的结果:

have_library: checking for magic_open() in -ltrue... -------------------- no

"gcc -o conftest -I. -I/usr/local/rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/x86_64-linux -I.    -g -O2  -fPIC   conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -L.  -rdynamic -Wl,-export-dynamic     -lruby-static -ltrue  -lrt -ldl -lcrypt -lm   -lc"
conftest.c: In function ‘t’:
conftest.c:3: error: ‘magic_open’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
/* end */

"gcc -o conftest -I. -I/usr/local/rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/x86_64-linux -I.    -g -O2  -fPIC   conftest.c  -L. -L/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -L.  -rdynamic -Wl,-export-dynamic     -lruby-static -ltrue  -lrt -ldl -lcrypt -lm   -lc"
/usr/bin/ld: cannot find -ltrue
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { magic_open(); return 0; }
/* end */

我想不出该怎么做才能让这个东西正常工作。

4个回答

19

我在Ubuntu 12.04上遇到了同样的问题。只需通过以下命令安装libmagic-dev软件包即可:

sudo apt-get install libmagic-dev

10
在Mac上,使用Homebrew:
sudo brew install libmagic

1
嘿,我仍然得到了 checking for magic_open() in -lmagic... no 有什么想法吗? - AJP
首先确保libmagic已经正确安装。尝试运行ls -al /usr/local/include/|grep magic命令并验证是否存在magic.h文件。 - troelskn
文件magic.h已经存在,但我仍然遇到了相同的错误。不过,我认为最近的ruby-filemagic的初始错误是这个:ld: library not found for -lgnurx clang: error: linker command failed with exit code 1(使用-v查看调用)。 - user2932688

9

我需要做的事情:

yum install file-devel

这显然包含了libmagic头文件,filemagic ruby gem需要这些文件才能编译。在此之后,它的工作效果非常好。


“file-devel” 确实是用于 “file-libs” 的开发包! - TNT

1

我在OpenSuse 11.3上遇到了同样的问题。这个方法有帮助:

zypper install file-devel

在这里添加一条评论,为那些通过在OpenSUSE Tumbleweed上安装失败的"ruby-magic"而来的人提供帮助。
  1. 如果需要的话,在Tumbleweed历史记录中搜索相关的旧软件包(例如https://download.opensuse.org/history/20230801/ - cat rpm.list,然后将软件包路径附加到URL以找到.rpm文件的下载路径)。我需要5.44版本的file-magic、libmagic1和file-devel。
  2. 在安装时,设置MAGIC_USE_SYSTEM_LIBRARIES环境变量(任意值)- 例如gem build ruby-magic.gemspec && MAGIC_USE_SYSTEM_LIBRARIES=true gem install ./ruby-magic-0.6.0.gem
- Momer

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