Вопрос

I want to use C-functions in my python program and the obvious way is to implement the libraries with "ctypes".

But there is a problem. In C I include different header files that the linker will link with the right libraries. But I only know the name of the header files, but for python I need to know the name of the library files, like "libxyz.so".

So how do I get the linker or whoever to tell me which libraries are used for the different header files?

Это было полезно?

Решение

ctypes dynamically loads the shared object or the DLL, so you need some how the shared object name. You may have a look at ctypes.util.find_library(name). For example:

>>> from ctypes.util import find_library
>>> 
>>> find_library('pthread')
'libpthread.so.0'
>>> 
>>> find_library('ssl')
'libssl.so.0.9.8'
>>> 
>>> find_library('png')
'libpng12.so.0'
>>> 
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top