简体   繁体   English

如何在python-cffi中使用共享动态库(在Linux中)?

[英]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: 我想知道的几件事:

  1. Is there some good starting point which I can refer for doing this (loading and using dynamic libraries using cffi)? 我有什么好的起点可以参考(使用cffi加载和使用动态库)吗? The docs on the official site talk about this, but I was looking if there was some concrete reference somewhere with some examples. 官方站点上的文档对此进行了讨论,但是我一直在寻找某处是否有一些示例的具体参考。 Or someone who might have tried it. 或尝试过的人。
  2. Can there a possible drawback to this approach? 这种方法可能存在缺点吗?

Thanks 谢谢

Two good starting points: 两个好的出发点:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM