Jump to content

Using python in C

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
BlueDream

BlueDream

    Newbie

  • Members
  • Pip
  • 4 posts
Hi,

I'm trying to wrap my head around piping in C - I've got a small C program that forks and pipes stuff from the child process to the parent process.

Currently the child process calls a C program that squirts out random numbers which then pipes the result to the parent process.

The parent process reads the pipe and simply prints the random number.

What I would like to do is then use this piped integer in a python program.

So firstly I think I have to include the python library within the C program.

#include <python2.4/Python.h>

then call python with:

Py_Initialize();

But when I call this the gcc compiler gives me the error:
undefined reference to 'Py_Initialize'

So I'm guessing that the header file I'm using is incorrect..?

the python version I'm using is:

Python 2.4.3 (#1, Jun 13 2006, 16:41:18)

Thanks.

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
Did you remember to link with the Python library?
If you're using GCC, add "-lpython2.4"

#3
BlueDream

BlueDream

    Newbie

  • Members
  • Pip
  • 4 posts
Hmmn, no I wasn't linking it on the command line with gcc.

I tried the example you gave.

:\gcc pipe.c -lpython2.4

and voila!

My code is not working, but at least I can see it's getting past that darn udefined variable problem.

Now all I need to do is figure out how to print the variable in python with PyRun_SimpleString( ..... ).

Thanks.