解决方案1:
#!/usr/bin/env pythonimport os,sys,time,refrom ctypes import *... ...def function1(): ... ... sStdPath = os.path.dirname(sStcPath) + "/libstdc++.so.6" stc_lib = CDLL(sStdPath)
解决方案二:
ctypes.cdll.LoadLibrary('/abs/path/to/a.so')ctypes.cdll.LoadLibrary('/abs/path/to/b.so')
方案三:
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 osos.chdir('/path/to/your/binaries')
Like this, the loader also finds other dynamic libraries like otherbinary.so
LD_LIBRARY_PATH不生效的原因:
31down voteaccepted | 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. |