views:

45

answers:

1

I want to use python's (2.6.5) ctypes with cygwin, but I don't know how to load a dll.

I tried various variants like

>>> 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  A: 

You won't be able to load an import library with the Python ctypes module; it has to be an actual DLL. I used both the cygwin crypt library and the crypt DLL import library as examples with a late model Cygwin on Win7.


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
jtp
thx, I didn't know how cygwin handles the dll stuff. Is there some magic function, whichs finds the correct librarys on all platform just by the name, e.g. "crypt"?
Florianx
You are welcome. I don't know if there is a cross-platform means way to specify a dynamic library at runtime. I had a similar problem with the Parrot VM and SQLite a while back. On Linux the shared library was libsqlite3.so, but on Windows it was sqlite3.dll. Although the file extension did not have to be specified in Parrot, the filename still differed by "lib," so my program still needed conditional statements to check for the operating system type in order to load the shared library cross platform. Linux mitigates the shared library handling somewhat through the use of symbolic links.
jtp