You are not logged in.

#1 2014-04-23 11:42:09

Caffeine
Member
Registered: 2014-04-23
Posts: 4

Converting Python To C with Cython

I am trying to convert a more complex Python script into C with C. But in order to get used to Cython i thought of trying first to convert a simple HelloWorld.py into C, so trivially it look some kind like this:

HelloWorld.py

def main():
	print("Hello, World!")

if __name__ == '__main__':
	main()

I am compiling the resuting C program like this:

HelloWorld.c

gcc HelloWorld.c -o HelloWorld

And what i always get is this:

HelloWorld.c:8:22: fatal error. pyconfig.h: No such file or directory compilation terminated.
 #include "pyconfig.h"
                      ^

I found a similiar post here, which unfortunately did not really help.

Offline

#2 2014-04-23 11:58:13

Caffeine
Member
Registered: 2014-04-23
Posts: 4

Re: Converting Python To C with Cython

Solved. For everybody who is interested:

Fix the Include in your Cython converted C-File, like this:

#include "python2.7/Python.h" instead of #include "Python.h".

Offline

#3 2014-04-23 12:36:06

Foucault
Member
From: Athens, Greece
Registered: 2010-04-06
Posts: 214

Re: Converting Python To C with Cython

Instead of touching automatically generated C files use pkg-config

gcc `pkg-config --libs --cflags python2` -c test.c -o test.o

or python3 if you want python 3.x

Offline

Board footer

Powered by FluxBB