ctypes for static libraries?

烂漫一生 提交于 2019-11-30 22:36:22

问题


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?

Thanks,

Mike


回答1:


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.




回答2:


I can't say for sure there are no modules out there, but the advantages of dynamic libraries (uses less space, can update without recompiling dependent programs) are such that you're probably better off doing just that.



来源:https://stackoverflow.com/questions/2983649/ctypes-for-static-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!