I have been trying to use a dll library from CNES in python.
My first approach was trough ctypes
and i did something like:
from ctypes import *
cdll.LoadLibrary("dll/propa64.dll")
This simple loading goes very smooth on windows but i have trouble on mac/linux. More specifically when i try to run the code on MacOS i get:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-6-74c6935de494> in <module>
----> 1 cdll.LoadLibrary("dll/propa64.dll")
~/opt/anaconda3/lib/python3.7/ctypes/__init__.py in LoadLibrary(self, name)
440
441 def LoadLibrary(self, name):
--> 442 return self._dlltype(name)
443
444 cdll = LibraryLoader(CDLL)
~/opt/anaconda3/lib/python3.7/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362
363 if handle is None:
--> 364 self._handle = _dlopen(self._name, mode)
365 else:
366 self._handle = handle
OSError: dlopen(dll/propa64.dll, 6): no suitable image found. Did find:
dll/propa64.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
/range/code_python/propa/dll/propa64.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
and in Linux(to be precise is a linux docker image on a macos host) i get:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-3-74c6935de494> in <module>
----> 1 cdll.LoadLibrary("dll/propa64.dll")
/opt/conda/lib/python3.7/ctypes/__init__.py in LoadLibrary(self, name)
440
441 def LoadLibrary(self, name):
--> 442 return self._dlltype(name)
443
444 cdll = LibraryLoader(CDLL)
/opt/conda/lib/python3.7/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error)
362
363 if handle is None:
--> 364 self._handle = _dlopen(self._name, mode)
365 else:
366 self._handle = handle
OSError: dll/propa64.dll: invalid ELF header
Now it is preatty clear that there is some sort of incompatibility on Linux and Macos for this dll. My question are:
- why is that?
- is there a way to make this library more "compatible" ?
I have been looking around a bit and maybe Cython could be useful but i'm not entirely sure. Thank in advance for the help!
Someone pointed out this: Importing a dll in python on Ubuntu but even though this could be a valid workaround i would rather prefer to solve the problem at is core.