Problem: embedding Python

M

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
 
T

thesamet

mmf said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,807
Members
48,797
Latest member
PeterSimpson
Top