def find_library(libname):
"""
Search for 'libname.so'.
Returns library loaded with ctypes.CDLL
Raises OSError if library is not found
"""
base_path = os.path.dirname(__file__)
lib, search_paths = None, []
so_extensions = [ ext for ext, _, typ in imp.get_suffixes()
if typ == imp.C_EXTENSION ]
for extension in so_extensions:
search_paths += [
os.path.abspath(os.path.normpath(
os.path.join( base_path, '..', libname + extension ))),
os.path.abspath(os.path.normpath(
os.path.join( base_path, '../..', libname + extension )))
]
for path in search_paths:
if os.path.exists(path):
lib = path
break
if not lib:
raise OSError('Cant find %s.so. searched at:\n %s' % (
libname, '\n'.join(search_paths)))
return ctypes.CDLL(lib)
评论列表
文章目录