Bootstrap

python动态加载so文件

解决方案1:

#!/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)

解决方案二:

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='./a
;