如何在Mac OS X上安装ruby-filemagic?

3
我找到了一些关于这个问题的已有问答,但是它们中的回答都不起作用。
尝试使用brew而不是ports在Snow Leopard上安装ruby-filemagic:https://dev59.com/U07Sa4cB1Zd3GeqP7eW1 在新的RHEL6服务器上安装ruby-filemagic gem时遇到困难:https://dev59.com/3Wkv5IYBdhLWcg3wzj41 它们都将此页面指向作为答案:https://gist.github.com/eparreno/1845561 但那也不起作用。我仍然会收到以下错误。
Building native extensions with: '--with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/'
This could take a while...
ERROR:  Error installing ruby-filemagic:
    ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/
checking for main() in -lgnurx... no
checking for magic_open() in -lmagic... 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.

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/2.0/usr/bin/ruby
    --with-magic-dir
    --without-magic-dir
    --with-magic-include=${magic-dir}/include
    --with-magic-lib=${magic-dir}/
    --with-gnurx-dir
    --without-gnurx-dir
    --with-gnurx-include
    --without-gnurx-include=${gnurx-dir}/include
    --with-gnurx-lib
    --without-gnurx-lib=${gnurx-dir}/
    --with-gnurxlib
    --without-gnurxlib
    --with-magiclib
    --without-magiclib


Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/ruby-filemagic-0.7.0 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/ruby-filemagic-0.7.0/ext/filemagic/gem_make.out

那么出了什么问题呢?在提到mkmf.log错误时,我在日志文件中看到了很多编译内容,所以我不知道错误具体在哪里。它的形式如下:

have_library: checking for main() in -lgnurx... -------------------- no

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L/usr/local/lib/ -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0  -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L/usr/local/lib/ -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0 -lgnurx  -lpthread -ldl -lobjc "
conftest.c:5:57: error: use of undeclared identifier 'main'
int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
                                                        ^
1 error generated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int t(void) { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
 6: int main(int argc, char **argv)
 7: {
 8:   if (argc > 1000000) {
 9:     printf("%p", &t);
10:   }
11: 
12:   return 0;
13: }
/* end */

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L/usr/local/lib/ -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0 -lgnurx  -lpthread -ldl -lobjc "
conftest.c:5:15: warning: implicit declaration of function 'main' is invalid in C99 [-Wimplicit-function-declaration]
int t(void) { main(); return 0; }
              ^
1 warning generated.
ld: library not found for -lgnurx
conftest.c:5:15: warning: implicit declaration of function 'main' is invalid in C99 [-Wimplicit-function-declaration]
int t(void) { main(); return 0; }
              ^
1 warning generated.
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int t(void) { main(); return 0; }
 6: int main(int argc, char **argv)
 7: {
 8:   if (argc > 1000000) {
 9:     printf("%p", &t);
10:   }
11: 
12:   return 0;
13: }
/* end */

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

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

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L/usr/local/lib/ -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0 -lmagic  -lpthread -ldl -lobjc "
conftest.c:5:57: error: use of undeclared identifier 'magic_open'
int t(void) { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
                                                        ^
1 error generated.
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int t(void) { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
 6: int main(int argc, char **argv)
 7: {
 8:   if (argc > 1000000) {
 9:     printf("%p", &t);
10:   }
11: 
12:   return 0;
13: }
/* end */

"xcrun clang -o conftest -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin14 -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/backward -I/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 -I. -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT    -g -Os -pipe -DHAVE_GCC_SYNC_BUILTINS conftest.c  -L. -L/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib -L/usr/local/lib/ -L. -L/usr/local/lib   -arch x86_64 -arch i386   -lruby.2.0.0 -lmagic  -lpthread -ldl -lobjc "
conftest.c:5:15: warning: implicit declaration of function 'magic_open' is invalid in C99 [-Wimplicit-function-declaration]
int t(void) { magic_open(); return 0; }
              ^
1 warning generated.
conftest.c:5:15: warning: implicit declaration of function 'magic_open' is invalid in C99 [-Wimplicit-function-declaration]
int t(void) { magic_open(); return 0; }
              ^
1 warning generated.
ld: warning: ignoring file /usr/local/lib//libmagic.dylib, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/lib//libmagic.dylib
Undefined symbols for architecture i386:
  "_magic_open", referenced from:
      _t in conftest-d6cdee.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
 1: #include "ruby.h"
 2: 
 3: /*top*/
 4: extern int t(void);
 5: int t(void) { magic_open(); return 0; }
 6: int main(int argc, char **argv)
 7: {
 8:   if (argc > 1000000) {
 9:     printf("%p", &t);
10:   }
11: 
12:   return 0;
13: }
/* end */

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

主要问题似乎是这样的。
conftest.c:5:57: error: use of undeclared identifier 'magic_open'
int t(void) { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }

我不懂C++,所以我不知道magic_open的问题是什么。
有任何想法吗?

1
sudo apt-get install libmagic-dev 有帮助吗? - Nishant
这是在Mac OS X上。真希望是Linux啊,不然早就过去了,嘿嘿。 - TinyGrasshopper
2个回答

11
几年后...在 Mac 上尝试这个方法。 使用 brew install libmagic 命令。 希望这能帮助其他遇到类似问题的人。

-2

我觉得你需要接受Xcode许可证。 例如,输入sudo clang并按照显示的步骤操作。


我认为Xcode许可证与原帖的问题无关。毕竟,clang似乎是正常工作的。 - WhiteViking

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