【问题标题】:Compiling a library for Ruby with SWIG on Mac OS X在 Mac OS X 上使用 SWIG 为 Ruby 编译库
【发布时间】:2011-03-05 04:26:58
【问题描述】:

我尝试编译以下库,一切顺利,直到最后一步。

/* File : computation.c */
int add(int x, int y) {
  return x + y;
}

/* File: computation.i */
%module computation
extern int add(int x, int y);

$ swig -ruby computation.i
$ gcc -c computation.c
$ gcc -c computation_wrap.c -I/opt/local/lib/ruby/1.8/i686-darwin10
$ gcc -shared computation.o computation_wrap.o -o computation.so

Undefined symbols:
  "_rb_str_cat", referenced from:
      _Ruby_Format_TypeError in computation_wrap.o
  "_rb_exc_new3", referenced from:
      _SWIG_Ruby_ExceptionType in computation_wrap.o
  "_rb_define_class_under", referenced from:
      _SWIG_Ruby_define_class in computation_wrap.o
      _SWIG_Ruby_define_class in computation_wrap.o
[...]
ld: symbol(s) not found
collect2: ld returned 1 exit status

我的配置:

$ sw_vers
ProductName:  Mac OS X
ProductVersion: 10.6.3
BuildVersion: 10D575
$ ruby -v
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]
$ swig -version
SWIG Version 1.3.40
Compiled with /usr/bin/g++-4.2 [i386-apple-darwin10.3.0]
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5646)

【问题讨论】:

    标签: c ruby macos osx-snow-leopard swig


    【解决方案1】:

    尝试以下标志来编译共享对象:

    $ gcc -bundle -flat_namespace -undefined suppress computation.o computation_wrap.o -o computation.so
    

    您可能还需要添加“-arch i386”,因为它看起来像是在 Snow Leopard 上运行 32 位 Ruby。

    【讨论】:

    • 我不得不将computation.so 更改为computation.bundle,但它成功了,谢谢!
    猜你喜欢
    • 2013-01-24
    • 1970-01-01
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    相关资源
    最近更新 更多