| Store | Cart

Embedding Python

From: Mark Tolonen <nos...@nospam.com>
Sat, 26 Mar 2005 10:38:01 -0800
"Markus Franz" <mf1987 at arcor.de> wrote in message 
news:576fb15a.0503260342.15ea4630 at posting.google.com...
> 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

This works for me on Redhat 9:

g++ x.cpp -o x -I/usr/include/python2.2 -pthread -lm
  -ldl -lutil /usr/lib/python2.2/config/libpython2.2.a

I discovered what libraries to link to by asking distutils:

import distutils.sysconfig
distutils.sysconfig.get_config_var('LIBS')
distutils.sysconfig.get_config_var('SYSLIBS')

g++ links to the right libraries for .cpp files.

-Mark 

Recent Messages in this Thread
Markus Franz Mar 26, 2005 11:42 am
Diez B. Roggisch Mar 26, 2005 01:52 pm
Markus Franz Mar 26, 2005 05:05 pm
Diez B. Roggisch Mar 26, 2005 05:06 pm
Mark Tolonen Mar 26, 2005 06:38 pm
Diez B. Roggisch Mar 26, 2005 06:47 pm
Mark Tolonen Mar 26, 2005 07:43 pm
Heiko Wundram Mar 26, 2005 09:51 pm
Heiko Wundram Mar 26, 2005 08:57 pm
Reinhold Birkenfeld Mar 26, 2005 08:06 pm
Mark Tolonen Mar 26, 2005 08:36 pm
Messages in this thread