How do you update this environment variable at runtime so that ctypes can load a library wherever? I've tried the following and neither seem to work.
from ctypes import * os.environ['LD_LIBRARY_PATH'] = "/home/starlon/Projects/pyCFA635/lib" os.putenv('LD_LIBRARY_PATH', "/home/starlon/Projects/pyCFA635/lib") lib = CDLL("libevaluator.so")
Set the LD_LIBRARY_PATH to include the directory or directories that contain your libraries.
ctypes exports the byref() function which is used to pass parameters by reference.
ctypes allows to create C callable function pointers from Python callables. These are sometimes called callback functions. First, you must create a class for the callback function, the class knows the calling convention, the return type, and the number and types of arguments this function will receive.
By the time a program such as Python is running, the dynamic loader (ld.so.1 or something similar) has already read LD_LIBRARY_PATH and won't notice any changes thereafter. So, unless the Python software itself evaluates LD_LIBRARY_PATH and uses it to build the possible path name of the library for dlopen()
or an equivalent function to use, setting the variable in the script will have no effect.
Given that you say it doesn't work, it seems plausible to suppose that Python does not build and try all the possible library names; it probably relies on LD_LIBRARY_PATH alone.
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