469,917 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Problem: embedding Python

mmf
Hallo!

I tried to use Python from C like it is described in the Python
Docmentation. So I wrote the following C source file:

#include <Python.h>
int
main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("print 'Hallo World!'\n");
Py_Finalize();
return 0;
}

I saved it as run.c and tried to compile it using the following
command:
gcc run.c

But that always results in a list of errors:

/tmp/cc1tmrPU.o(.text+0x1d): In function `main':
: undefined reference to `Py_Initialize'
/tmp/cc1tmrPU.o(.text+0x2a): In function `main':
: undefined reference to `PyRun_SimpleString'
/tmp/cc1tmrPU.o(.text+0x32): In function `main':
: undefined reference to `Py_Finalize'

What am I doing wrong? Can you help me?

Tanks.

Best regards,
Markus

Jul 19 '05 #1
1 1345
mmf wrote:
Hallo!

I tried to use Python from C like it is described in the Python
Docmentation. So I wrote the following C source file:

#include <Python.h>
int
main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("print 'Hallo World!'\n");
Py_Finalize();
return 0;
}

I saved it as run.c and tried to compile it using the following
command:
gcc run.c

But that always results in a list of errors:

/tmp/cc1tmrPU.o(.text+0x1d): In function `main':
: undefined reference to `Py_Initialize'
/tmp/cc1tmrPU.o(.text+0x2a): In function `main':
: undefined reference to `PyRun_SimpleString'
/tmp/cc1tmrPU.o(.text+0x32): In function `main':
: undefined reference to `Py_Finalize'

What am I doing wrong? Can you help me?

Tanks.

Best regards,
Markus


You should link with Python's shared object (replace with your version
of Python):
gcc -o run run.c -I/usr/include/python2.4 -lpython2.4

--
Are you a riddle lover?
Try http://www.pythonchallenge.com
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Alicia Haumann | last post: by
6 posts views Thread by John Dean | last post: by
reply views Thread by DevEng | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.