HELP for embedding Python in C prog

Gerhard Häring gh_pythonlist at gmx.de
Thu Oct 25 09:19:15 EDT 2001


On Thu, Oct 25, 2001 at 12:15:15PM -0400, dag4004 wrote:
> hello,
> 
> I want to embedded Python in a C prog. I try with the Programming Python 
> (O'REILLY).
> Here is the exemple : basic1.c
> 
> #include <Python.h>
> 
> int main(void)
> {
>         Py_Initialize();
>         PyRun_SimpleString("a=1");
>         PyRun_SimpleString("print a");
>         return 0;
> }
> 
> the makefile
> 
> PY = /usr/src/Python-2.1.1
> 
> PLIBS = $(PY)/libpython2.1.a
> 
> basic1: basic1.o
>         gcc -g basic1.o $(PLIBS) -lm -o basic1
> 
> basic1.o: basic1.c
>         gcc basic1.c -c -g -I$(PY)/Include -I$(PY)/.
> 
> And what i get :
> 
> # make
> gcc -g basic1.o /usr/src/Python-2.1.1/libpython2.1.a -lm -o basic1
> /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function 
> `posix_tmpnam':/usr/src/Python-2.1.1/./Modules/posixmodule.c:4212: the use 
> of `tmpnam_r' is dangerous, better use `mkstemp'
> /usr/src/Python-2.1.1/libpython2.1.a(posixmodule.o): In function 
> `posix_tempnam':
> /usr/src/Python-2.1.1/./Modules/posixmodule.c:4168: the use of `tempnam' is 
> dangerous, better use `mkstemp'
> /usr/src/Python-2.1.1/libpython2.1.a(dynload_shlib.o): In function 
> `_PyImport_GetDynLoadFunc':
> /usr/src/Python-2.1.1/Python/dynload_shlib.c:86: undefined reference to 
> `dlopen'/usr/src/Python-2.1.1/Python/dynload_shlib.c:94: undefined 
> [...]

You need to link against additional libraries. To know which ones, try
this at an interactive Python prompt:

>>> from distutils.sysconfig import get_config_var
>>> print get_config_var("LIBS") + " " + get_config_var("SYSLIBS")
-lpthread -ldl  -lutil -lm

Gerhard
-- 
mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    http://www.cs.fhm.edu/~ifw00065/    OpenPGP public key id 86AB43C0
public key fingerprint: DEC1 1D02 5743 1159 CD20  A4B6 7B22 6575 86AB 43C0
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))




More information about the Python-list mailing list