Why "undefined reference to `Py_Initialize' " error?

Bryan Mongeau bryan at eevolved.com
Mon Feb 5 20:37:24 CET 2001


Have you tried explicitly including "pythonrun.h"?
That file specifies Py_Initialize I think.

Bill Xu wrote:

> Hi, Buddies:
> 
> Please help me with Python embeded C++ problem:
> I compile the following file with gcc -I /usr/local/include/python2.0/
> basic1.c
> It gives me " undefined reference to `Py_Initialize' " error,
> Do I miss some setting in Python 2.0 or miss some package?
> I can't find my Modules, Python ... directorys in my python 2.0 directory.
> Please give me some hints! Thanks in advance.
> 
> Bill
> 
> The makefile with this sample is:
> PY = /usr/include/python1.5
> 
> PLIBS = $(PY)/Modules/libModules.a \
>         $(PY)/Python/libPython.a \
>         $(PY)/Objects/libObjects.a \
>         $(PY)/Parser/libParser.a
> 
> POBJS = $(PY)/Modules/config.o $(PY)/Modules/getpath.o
> 
> basic1: basic1.o
>  cc -g basic1.o $(POBJS) $(PLIBS) -lm -o basic1
> 
> basic1.o: basic1.c
>  cc basic1.c -c -g -I$(PY)/Include -I$(PY)/.
> 
> 
> 
> $ gcc -I /usr/local/include/python2.0/ basic1.c
> /tmp/ccNyWd2r.o: In function `main':
> /tmp/ccNyWd2r.o(.text+0x2d): undefined reference to `Py_Initialize'
> collect2: ld returned 1 exit status
> 
> 
> #include "Python.h"
> char *getprogramname() { return "basic1"; }
> 
> main() {
>     printf("%s\n", getprogramname());
>     Py_Initialize();
>     // PyRun_SimpleString("import string");
>     // PyRun_SimpleString("print string.uppercase");
>     // PyRun_SimpleString("x = string.uppercase");
>     // PyRun_SimpleString("print string.lower(x)");
> }
> 
> 
> 
> 
> 
> 
> 

-- 
<==================================>
Bryan Mongeau
Lead Developer, Director
eEvolved Real-Time Technologies Inc.
www.eevolved.com
<==================================>

"Now he has departed from this strange world a little ahead of me. That 
means nothing. People like us, who believe in physics, know that the 
distinction between past, present, and future is only a stubbornly 
persistent illusion."-- Einstein




More information about the Python-list mailing list