4

我正在尝试为这个库创建一个 python 绑定:

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

我正在使用 swig,代码如下:

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

我跑

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

我编译

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

但是当我运行 python 并导入它时,我得到:

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

我该如何解决?

谢谢。

4

1 回答 1

5

那是被破坏的名字:

hosters::hostersLink::getLink(int)

确保您已定义该功能。

好的,我仔细研究了主机 0.6。头文件声明了两个getLink方法:

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

但是源文件只声明了第一个:

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

但是 SWIG 正在为这两个功能创建包装器,这会搞砸事情。我建议做以下两件事之一:

  1. 删除std::string getLink(int n);未定义的方法。
  2. 添加定义std::string getLink(int n) { ... }
于 2010-03-24T22:24:53.420 回答