embedding python in C

Lamy Bertrand b_lamy at club-internet.fr
Mon Nov 12 05:22:34 CET 2001

I can't manage to compile my C file that use Python C functions :

here is some code :

#include <Python.h>

int main(int arg, char** argv) {
    PyObject* p = PyFloat_FromDouble(1.0);
    PyObject* f = PyTuple_New(5);

I compile that file like this :

gcc -g -Wall -Wstrict-prototypes -Xlinker -export-dynamic 
-I/usr/include/python2.2 -L/usr/lib/python2.2/config -ldl -lutil
-o./test ./test.c

and I have that error :

/tmp/ccCbe9OS.o: In function `main':
/home/blam/c/./testp.c:54: undefined reference to `PyFloat_FromDouble'
/home/blam/c/./testp.c:56: undefined reference to `PyTuple_New'
collect2: ld returned 1 exit status

I do not understand cause the libpython2.2.a is linked and must normally 
defines the functions PyFloat_FromDouble and PyTuple_New ?!?

- Blam

More information about the Python-list mailing list