[英]How to use shared dynamic libraries with python-cffi (in linux)?
OS: CentOS 6 (64bit) 作业系统:CentOS 6(64bit)
I have a dynamic library (.so) in C. And I want to create an abstraction layer of Python over it and then use it to implement my logic. 我在C中有一个动态库(.so)。我想在其上创建一个Python抽象层,然后使用它来实现我的逻辑。 I have decided to use CFFI for this since it doesn't deal with any kind of dsl (domain specific language).
我决定为此使用CFFI,因为它不处理任何种类的dsl(域特定语言)。
Couple of things I wanted to know: 我想知道的几件事:
Thanks 谢谢
Two good starting points: 两个好的出发点:
The CFFI documentation, and specifically the ABI out of line example: https://cffi.readthedocs.org/en/latest/overview.html#out-of-line-example-abi-level-out-of-line CFFI文档,特别是ABI脱机示例: https ://cffi.readthedocs.org/en/latest/overview.html#out-of-line-example-abi-level-out-of-line
My CFFI example repository: https://github.com/wolever/python-cffi-example 我的CFFI示例存储库: https : //github.com/wolever/python-cffi-example
Between the two you shouldn't have too much trouble putting together your wrapper. 在这两者之间,组装包装纸应该没有太大的麻烦。
And to your second question: if the shared library you're wrapping is very simple (ex, a few function calls, simle data structures) you might find ctypes
simpler (as it's part of the standard library). 关于第二个问题:如果要包装的共享库非常简单(例如,一些函数调用,简单的数据结构),您可能会发现
ctypes
更简单(因为它是标准库的一部分)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.