Embedding python in C under Fedora 16.

About the source code.
I will try to embed python in C application. I will use a simple python script.
This is a simple example using pygame python module.

Make a new folder and named Python_C using these commands in the shell:

Let’s see the C source code.

You can read more about functions and docs here.
I named the file test001.c.
About compiling.
I saw many topics where the people tell us about the solution to compile is this:

You can get this error:

My opinion is not the correct way. See below my solution.
First, we use this:

You will have two output and you will use them. In my case is:

The result is test001. I run the application with:

… and is working well, see the screenshot below:
python and c image
About errors.
First, the C source code can give some errors:

This error is because you not use return 0;
Another error is this:

If you don’t use this int main() to return type of main function.
This warning error is enabled by -Wall compile option.
That was, for now, I will return with tutorials on the subject.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.