Hei
Hei

Reputation: 1894

Specifying Python Headers and Library for SWIG

I have two versions of python installed 2.7 and 3.3.

And when I tried to generate the wrapper with SWIG 1.3.4, I did something like this:

swig -c++ -python -I/opt/rh/python33/root/usr/include/python3.3m mylib.swig

And then, I tried to compile it with g++ 4.6

g++ -L/opt/rh/python33/root/usr/lib64 -Wl,-Bstatic -lz -lboost_date_time-mt -Wl,-Bdynamic -lpython3.3m -lbz2 -lpthread -lrt -ldl -O2 -fPIC -shared mylib_wrap.cxx -I.. -I/opt/rh/python33/root/usr/include/python3.3m -I/server/zodiac/include -std=gnu++0x -o _mylib.so

But then, I got error like this:

mylib_wrap.cxx: In function ‘swig_module_info* SWIG_Python_GetModule()’:
mylib_wrap.cxx:2453:51: error: ‘PyCObject_Import’ was not declared in this scope
mylib_wrap.cxx: In function ‘void SWIG_Python_SetModule(swig_module_info*)’:
mylib_wrap.cxx:2522:92: error: ‘PyCObject_FromVoidPtr’ was not declared in this scope
mylib_wrap.cxx: In function ‘swig_type_info* SWIG_Python_TypeQuery(const char*)’:
mylib_wrap.cxx:2545:60: error: ‘PyCObject_AsVoidPtr’ was not declared in this scope
mylib_wrap.cxx:2550:51: error: ‘PyCObject_FromVoidPtr’ was not declared in this scope

Then, I looked into Python 2.7's and 3.3's headers. I noticed that those expressions are defined in Python 2.7's headers but not 3.3.

So it seems to me even though I specified the include path to Python 3.3 when I asked SWIG to generate the wrapper, it still tried to use 2.7.

Any idea how to fix this?

Thanks!

Upvotes: 2

Views: 674

Answers (1)

SWIG 1.3.4 is ancient. It's not compatible with Python 3.3. You need to use a newer version of SWIG if you want to produce code that is compatible.

Upvotes: 2

Related Questions