I'm trying to work with a library that is compiled to /usr/local/lib/libName.so
but while running the python script that needs this file for:
from ctypes import CDLL
[...]
__lib = CDLL('libName.so')
I get:
OSError: libName.so: cannot open shared object file: No such file or directory
So i would like to know where i need to copy the .so file so that this CDLL call works properly.
ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.
ctypes is the de facto standard library for interfacing with C/C++ from CPython, and it provides not only full access to the native C interface of most major operating systems (e.g., kernel32 on Windows, or libc on *nix), but also provides support for loading and interfacing with dynamic libraries, such as DLLs or ...
cdll. msvcrt loads msvcrt. dll , which is a library that ships as part of Windows. It is not the C runtime that Python links with, so you shouldn't call the malloc/free from msvcrt . For example, for Python 2.6/3.1, you should be using ctypes.
ctypes ([Python 3.5]: ctypes - A foreign function library for Python), uses dlopen ([man7]: DLOPEN(3)) in order to load libraries, which delegates the loading (and implicitly finding) task to the Lnx loader.
The paths to search for .sos is very well explained in [man7]: LD.SO(8). Here's what it states about default ones:
- In the default path /lib, and then /usr/lib. (On some 64-bit architectures, the default paths for 64-bit shared objects are /lib64, and then /usr/lib64.)
Ways (most common) to solve your problem:
__lib = CDLL("/usr/local/lib/libName.so")
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With