From: ptkwt@... (Phil Tomson) Date: 2004-08-19T08:35:54+09:00 Subject: Re: swig problem with init In article <20040818221509.GA70952@freeze.org>, wrote: >I have an innocuous swig/ruby case that is causing me some grief. >The problem is probably obvious, but I'm not seeing the solution >right now. > >I have a .i file that defines a module > > cat itkdb.i > /* itkdb.i */ > %module ITKDb > > %{ > %} > >This generates a wrapper with the following lines of interest: > > #define SWIG_init Init_ITKDb > #define SWIG_name "ITKDb" > > #ifdef __cplusplus > extern "C" > #endif > SWIGEXPORT(void) Init_ITKDb(void) { > int i; > > SWIG_InitRuntime(); > mITKDb = rb_define_module("ITKDb"); > > for (i = 0; swig_types_initial[i]; i++) { > swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]); > SWIG_define_class(swig_types[i]); > } > > } > >I compile this against a vendor supplied library and try to load the .so >file and get: > > ruby -r itkdb -e {} > ./itkdb.so: /usr/lib/libruby.so.1.8: undefined symbol: Init_itkdb - > ./itkdb.so (LoadError) > >Can someone tell me what I'm doing wrong here? > Hmmmmm... Some quick guesses: In your wrapper file you've got this declaration: > SWIGEXPORT(void) Init_ITKDb(void) { While the error says it's looking for the symbol: Init_itkdb -------^^^^ So there seems to be a mismatch between ITKDb and itkdb... I would try changing the .i file to: %module itkdb %{ %} Although it does seem a bit backward... If I recall correctly, what happens is that when you define '%module itkdb' you'll get a Ruby module called Itkdb (uppercased). In your case you called it ITKDb and it seems to have lowercased it. What happens when you do: nm itkdb.so | grep Init ? Does it have entries for both Init_ITKDb (defined) and Init_itkdb (undefined)? Also, what version of swig are you running? Phil