Embedding Python

Markus Franz mf1987 at arcor.de
Sat Mar 26 06:42:59 EST 2005


Hi!

I wanted to run some Python code from inside a C program, so I did it
like it was explained in the Python manual:

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

Then I tried to compile this by using the command: gcc halloworld.cpp
But everytime I get the following errors:

/home/mmf/tmp/ccVD2V4h.o(.text+0x1d): In function `main':
: undefined reference to `Py_Initialize'
/home/mmf/tmp/ccVD2V4h.o(.text+0x2a): In function `main':
: undefined reference to `PyRun_SimpleString'
/home/mmf/tmp/ccVD2V4h.o(.text+0x32): In function `main':
: undefined reference to `Py_Finalize'
/home/mmf/tmp/ccVD2V4h.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

What am I doing wrong?

Markus



More information about the Python-list mailing list