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.
Using python in C
Started by BlueDream, May 04 2008 04:07 AM
2 replies to this topic
#1
Posted 04 May 2008 - 04:07 AM
|
|
|
#2
Posted 04 May 2008 - 04:17 AM
Did you remember to link with the Python library?
If you're using GCC, add "-lpython2.4"
If you're using GCC, add "-lpython2.4"
#3
Posted 04 May 2008 - 06:02 AM
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.
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.


Sign In
Create Account

Back to top









