Search code examples
pythonstatic-librariesctypes

ctypes for static libraries


I'm attempting to write a Python wrapper for poker-eval, a C static library. All the documentation I can find on ctypes indicates that it works on shared/dynamic libraries. Is there a 'ctypes' for static libraries?

I know about Cython, but should I use that or recompile the poker-eval into a dynamic library so that I can use ctypes?


Solution

  • The choice is really up to you. If you have the ability to recompile the library as a shared object, I would suggest that, because it will minimize the non-python code you have to maintain. Otherwise, you'll want to build a python extension module that links to the static library and wraps the functions it exposes.

    You mentioned Cython; here's the relevant manual page if you go that route:

    http://docs.cython.org/src/tutorial/clibraries.html

    There's also SWIG and Pyrex.