trying to use swig for the first time

Gary Wilson Jr gdub at ece.utexas.edu
Mon Jan 23 15:00:23 EST 2006


...I have some C code (foo.c and foo.h) that I would like to be able to access 
using python.

I've written my interface file (foo.i) like so:
%module foo
%{
#include "foo.h"
%}
%include "foo.h"

I then do the following on the command line:
$ swig -python foo.i
$ gcc -c foo.c foo_wrap.c -I /usr/include/python2.4
$ ld -shared foo.o foo_wrap.o -o _foo.so

Then when I try importing the module into python:
$ python -c "import foo"
Traceback (most recent call last):
   File "<string>", line 1, in ?
   File "foo.py", line 5, in ?
     import _foo
ImportError: ./_foo.so: undefined symbol: EVP_DecodeBlock

Now, EVP_DecodeBlock can be found in /usr/include/openssl/evp.h:
int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);

And evp.h in included in foo.h:
#include <openssl/evp.h>

What am I doing wrong here?
Do I need to include more in the interface file?

I tried adding the EVP_DecodeBlock declaration to the interface file like so:
%module foo
%{
#include "foo.h"
extern int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
%}
%include "foo.h"
extern int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);

But this led to the exact same error when trying to import the python module.



More information about the Python-list mailing list