2010-06-17 10 views
1

J'ai essayé de compiler la bibliothèque suivante et tout s'est bien passé jusqu'à la dernière étape.Compilation d'une bibliothèque pour Ruby avec SWIG sous Mac OS X

/* 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 

Ma configuration:

$ 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) 

Répondre

2

Essayez les options suivantes pour la compilation de l'objet partagé:

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

Vous pouvez aussi besoin d'ajouter "-arch i386" car il semble que vous 'est en cours d'exécution 32-bit Ruby sur Snow Leopard.

+1

J'ai dû changer de calcul.so à calcul.bundle mais alors ça a marché, merci! –