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

时间:2015-08-23 05:37:52

标签: c++ ruby-on-rails ruby macos

我发现了一些问题,但是没有一个问题可以解决。

Trying to install ruby-filemagic on Snow Leopard using brew rather than ports

Having difficulty installing ruby-filemagic gem on new RHEL6 server

他们都指向此页面作为答案

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的问题是什么

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

几年后...在Mac上尝试。

brew install libmagic

希望这可以帮助其他任何遇到此问题的人。

答案 1 :(得分:-1)

我认为您需要接受xcode许可 例如,键入(x^T)PQx并按照显示的过程