views:

213

answers:

1

I'm trying to make a python binding for the this library:

http://code.google.com/p/hosterslib/.

I'm using swig, heres is the code:

%module pyhosters    
%{    
#include "hosters/hosters.hpp"    
%}    
%include "hosters/hosters.hpp"

I run

swig -c++ -python -o swig_wrap.cxx swig.i

and I compile with

g++ -O2 -fPIC -shared -o _pyhosters.so swig_wrap.cxx python-config --libs --cflags -lhosters -lcln -lhtmlcxx pkg-config libglog --libs --cflags -I/usr/include/python2.6 -Wall -Wextra

But when I run python and I import it, I get:

>>> import pyhosters    
Traceback (most recent call last):    
  File "<input>", line 1, in <module>    
  File "./pyhosters.py", line 7, in <module>    
    import _pyhosters    
ImportError: ./_pyhosters.so: undefined symbol: _ZN7hosters11hostersLink7getLinkEi

How can I solve that?

Thanks.

+2  A: 

That is the mangled name of:

hosters::hostersLink::getLink(int)

Make sure you have defined that function.

Okay, I took a closer look at hosters 0.6. The header files declares two getLink methods:

std::string getLink(void);
std::string getLink(int n);

But the source file only declares the first one:

std::string hostersLink::getLink(void) {return Link;}

But SWIG is creating wrappers for both of those functions which screws things up. I recommend doing one of two things:

  1. Delete the std::string getLink(int n); method as it's undefined.
  2. Add a definition for std::string getLink(int n) { ... }
R Samuel Klatchko
Yes, it should be defined with the option "-lhosters".
Eduardo
@Eduardo - it *should* but it's **not** defining it. I've included more information.
R Samuel Klatchko
Thank you, I declared the second one accidentaly, thank you for taking your time.
Eduardo
@Eduardo - you're welcome.
R Samuel Klatchko