简体   繁体   English

有没有理由说Python的ctypes.CDLL无法从C头文件自动生成重定型和argtypes?

[英]Is there a reason why Python's ctypes.CDLL cannot automatically generate restype and argtypes from C header files?

For example, it would be nice to be able to do this: 例如,能够这样做会很高兴:

from ctypes import CDLL
mylib = CDLL('/my/path/mylib.so',header='/some/path/mylib.h')

instead of 代替

from ctypes import *
mylib = CDLL('/my/path/mylib.so')
mylib.f.restype = c_double
mylib.f.argtypes = [c_double, c_double]
mylib.g.restype = c_int
mylib.g.argtypes = [c_double, c_int]

My experience with python suggests that either something very close to this has been done already and I just haven't been able to find it, or that there is a good reason not to. 我对python的经验表明,已经完成了与此非常接近的事情并且我无法找到它,或者有充分的理由不这样做。 Are either of these the case? 这些都是这种情况吗?

I asked myself the same question and before I traveled down that road too far, I ran into ctypesgen: 我问自己同样的问题,在我走过这条路太远之前,我遇到了ctypesgen:

http://code.google.com/p/ctypesgen/ http://code.google.com/p/ctypesgen/

It will handle all of this for you, although you will need to do a little learning up front. 虽然你需要先做一点学习,但它会为你处理所有这些。 We use ctypesgen to generate one version of the Python bindings for the Subversion bindings. 我们使用ctypesgen为Subversion绑定生成一个版本的Python绑定。 It works very well. 它工作得很好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用Ctypes.cdll导入DLL - cannot import DLL with Ctypes.cdll ctypes.CDLL() 适用于 anaconda python 安装,但不适用于“原始” python 安装 - ctypes.CDLL() works from anaconda python installation but not from "raw" python installation Paradoxon:导入时在 Python 的 ctypes.CDLL 上无声崩溃,但在直接运行时不会崩溃 - 这怎么可能? - Paradoxon: silent crash on Python's ctypes.CDLL when importing, but not when running directly - how is this possible? python setup.py build ctypes.CDLL:无法打开共享 object 文件:没有这样的文件或目录 - python setup.py build ctypes.CDLL: cannot open shared object file: No such file or directory 使用python ctypes.CDLL()从其他目录加载.dll时出错 - Error when loading .dll from a different directory using python ctypes.CDLL() 我应该如何使用 python ctypes.CDLL 从.so 调用 function? - How should I call a function from .so using python ctypes.CDLL? When calling a c function using ctypes.CDLL in Python, the function always gets 0 passed along as argument - When calling a c function using ctypes.CDLL in Python, the function always gets 0 passed along as argument 在python中的共享库上使用ctypes.CDLL时出错 - Error using ctypes.CDLL on shared library in python Python ctypes.CDLL 成功加载了我的共享库,但我看不到任何 C++ 函数 - Python ctypes.CDLL loads my shared library successfully, but I can't see any of my C++ functions ctypes.CDLL() 和 ctypes.cdll.LoadLibrary() 有什么区别? - What is the difference between ctypes.CDLL() and ctypes.cdll.LoadLibrary()?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM