Call external C library/functions using Cython

27 views
Skip to first unread message

Peiyao Li

unread,
Mar 13, 2018, 2:32:29 PM3/13/18
to cython-users
Hi, all,

Recently, in our project, we need to call some functions/libraries written in C. I have read the official documents and tutorials but am still unclear about some technical things.
In my project, let's say the API function is  only "foo.c" and its header file "foo.h" and I only to call the function "int detect(int num)" in the python program. However, the tricky part is "foo.c" also call other C functions, for instance, "tools.c" (tools.h)
Here is my question, in pyd file and pyx file, do I have to write the API wrapper codes for tools.c as well?

Best
Peiyao

Stefan Behnel

unread,
Mar 16, 2018, 3:41:04 AM3/16/18
to cython...@googlegroups.com
Peiyao Li schrieb am 13.03.2018 um 14:53:
> Recently, in our project, we need to call some functions/libraries written
> in C. I have read the official documents and tutorials but am still unclear
> about some technical things.
> In my project, let's say the API function is only *"foo.c"* and its header
> file* "foo.h"* and I only to call the function "*int detect(int num)*" in
> the python program. However, the tricky part is *"foo.c"* also call other C
> functions, for instance, *"tools.c" (tools.h)*
> Here is my question, in pyd file and pyx file, do I have to write the API
> wrapper codes for *tools.c* as well?

No, you only need to declare to Cython what you are using in your Cython
code. The C compiler then sees the whole picture. Just make sure that the
other .c files get compiled and linked in by distutils.

Stefan
Reply all
Reply to author
Forward
0 new messages