Cython: function call from external C file

After Cython "Hello World" and an example of calling a function in C-math libraries here , I really want to do this in order to have my C-code in a separate file and use it with Cython. Following this , I modify the setup.py file:

sourcefiles = ['hello2_caller.pyx', 'hello2.c'] 

This is hello2.c (main only for compilation and testing separately), although this product is not available for the test:

 #import <stdio.h> void f() { printf("%s", "Hello world!\n"); } int main(int argc, const char* argv[]) { f(); return 0; } 

This is hello2_caller.pyx

 cdef extern from "hello2.c": void f() cpdef myf(): f() 

I get:

 In file included from hello2_caller.c:219: hello2.c:3: warning: function declaration isn't a prototype 

So, I think that I can not provide the header in some way .. although it just feeds setup.py, a standard header such as "hello2.h" does not work. Can you point me to a working example or explain what I'm doing wrong. Thanks.

+7
source share
1 answer

Thanks to the help of the Cython user list here .
My entry is here .

Bottom line: this is only a warning, which is not fixed by the declaration of f (), but the compiled .so works. I'm still not sure how you provided the .h file for Cython or if there is a better way to do this.

And there are a couple of errors: there should be #include and not list the .c file in sourcfiles.

+4
source

All Articles