#!/usr/bin/env python import os,sys,time,re from ctypes import * ... ... def function1(): ... ... sStdPath = os.path.dirname(sStcPath) + "/libstdc++.so.6" stc_lib = CDLL(sStdPath)
Compile your binary with a rpath relative to the current working directory like:
gcc -shared -o yourbinary.so yoursource.c otherbinary.so \ -Wl,-rpath='.',-rpath='./another/relative/rpath' -fpic
Then, you are able to change the working directory in python at runtime with:
import os os.chdir('/path/to/your/binaries')
Like this, the loader also finds other dynamic libraries like otherbinary.so
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
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.