tags:

views:

65

answers:

2

HI all

I am trying to use SWIG to export C++ code to Python. The C sample I read on the web site does work but I have problem with C++ code.

Here are the lines I call

swig -c++ -python SWIG_TEST.i
g++ -c -fPIC SWIG_TEST.cpp SWIG_TEST_wrap.cxx -I/usr/include/python2.4/
gcc --shared SWIG_TEST.o SWIG_TEST_wrap.o -o _SWIG_TEST.so -lstdc++

When I am finished I receive the following error message

ImportError: ./_SWIG_TEST.so: undefined symbol: Py_InitModule4

Do you know what it is?

A: 

you might try building the shared library using gcc

g++ -shared SWIG_TEST.o SWIG_TEST_wrap.o -o _SWIG_TEST.so

rather than using ld directly.

Sam Miller
+1  A: 

It looks like you aren't linking to the Python runtime library. Something like adding -lpython24 to your gcc line. (I don't have a Linux system handy at the moment).

Mark Tolonen