Can Cython Interface with C DLLs?

1,558 views
Skip to first unread message

Jonathan Buck

unread,
Oct 9, 2015, 7:50:30 PM10/9/15
to cython-users
Does Cython provide an interface to external C DLLs? Examples abound for linking Cython to C via C *.h header files, but I can't find much in the way of C DLLs. In a nutshell, I want to make use of a dll someone has create to leverage a large amount of numerical calculations. 

Suppose I do this:

# hello.c

#include <stdio.h>

main
()
{
  printf
("Hello World!\n");
}  

gcc-c hello.c


1. Gcc shared o hello.dll hello.o

Now I've got a dll...but it's not clear to me how to utilize in Python via Cython. I've seen a couple examples to do this leveraging ctypes, but my understanding is that's more dangerous and requires more manual intervention. 


Robert Bradshaw

unread,
Oct 9, 2015, 8:09:14 PM10/9/15
to cython...@googlegroups.com
Yes, see http://docs.cython.org/src/tutorial/clibraries.html . You'll
have to list your 'hello' library in the libraries section of your
setup.py.
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "cython-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to cython-users...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Chris Barker

unread,
Oct 13, 2015, 12:09:02 PM10/13/15
to cython-users
On Fri, Oct 9, 2015 at 5:08 PM, Robert Bradshaw <robe...@gmail.com> wrote:
Yes, see http://docs.cython.org/src/tutorial/clibraries.html . You'll
have to list your 'hello' library in the libraries section of your
setup.py.

It's on that page, but to be clear here -- you will also need to put Cython declarations in for anything you want to call from the dll. This is exactly the same as if you are calling code you compile in yourself (i.e. you need the C *.h for the dll)-- the only difference is how it is linked.

-CHB



--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris....@noaa.gov
Reply all
Reply to author
Forward
0 new messages