Compiling a program the embeds python
Ben Lamb
news03 at zurgy.org
Tue Apr 22 06:19:00 EDT 2003
I'm trying to compile an example program written in C that embeds Python.
The porgram is:
#include <Python.h>
int main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is ',ctime(time())\n");
Py_Finalize();
return 0;
}
I use the following to compile it:
ben at localhost:~/prog/pyembed$ gcc -I/usr/local/include/python2.2
-L/usr/local/lib/python2.2/config -Xlinker -export-dynamic -lm -lpython2.2
-ldl -lpthread -lutil pyembed.c
/tmp/ccLcdPKW.o: In function `main':
/tmp/ccLcdPKW.o(.text+0x7): undefined reference to `Py_Initialize'
/tmp/ccLcdPKW.o(.text+0x14): undefined reference to `PyRun_SimpleString'
/tmp/ccLcdPKW.o(.text+0x1c): undefined reference to `Py_Finalize'
collect2: ld returned 1 exit status
I installed Python 2.2 on my Linux system by compiling it from sources with
the default options. I've tried using GNU C 2.95 and 3.2, ld 2.12.90 but
get the same errors.
Python runs fine on the system and I have successfully built other programs,
such as modpython, that embed it. modpython seems to build itself using
exactly the same options as I am trying above.
There are no libpython.so files on my system, just libpython2.2.a that lives
in /usr/local/lib/python2.2/config
Please can someone point out what I am doing wrong.
Thanks,
Ben Lamb.
More information about the Python-list
mailing list