在Cygwin中使用python.ctypes
我想在Cygwin环境下使用Python(2.6.5)的ctypes库,但我不知道怎么加载一个dll文件。
我尝试了各种不同的方法,比如:
>>> form ctypes import *
>>> cdll.LoadLibrary("/lib/libcairo.dll.a")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Permission denied
1 个回答
4
你不能用Python的ctypes模块加载一个导入库;它必须是一个真正的DLL文件。我用的是Cygwin的加密库和加密DLL导入库作为例子,这些都是在Win7上的新版本Cygwin中使用的。
Python 2.6.5 (r265:79063, Jun 12 2010, 17:07:01)
[GCC 4.3.4 20090804 (release) 1] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> cdll.LoadLibrary('cygcrypt-0.dll')
<CDLL 'cygcrypt-0.dll', handle 380000 at 7ef4564c>
>>>
>>>
>>> cdll.LoadLibrary('libcrypt.dll.a')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.6/ctypes/__init__.py", line 431, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.6/ctypes/__init__.py", line 353, in __init__
self._handle = _dlopen(self._name, mode)
OSError: Permission denied