# HG changeset patch # User Maciej BliziƄski # Date 1382283238 -3600 # Sun Oct 20 16:33:58 2013 +0100 # Node ID e0baa25c88ac24b01e496f838c309d2f6a2bc74c # Parent 34986f55a32d1bec5f1c3695fd0a53469db03625 find_library looks into Python binary's RPATH when looking for shared libraries diff -r 34986f55a32d -r e0baa25c88ac Lib/ctypes/util.py --- a/Lib/ctypes/util.py Sun Oct 20 17:25:34 2013 +0300 +++ b/Lib/ctypes/util.py Sun Oct 20 16:33:58 2013 +0100 @@ -114,16 +114,23 @@ if sys.platform == "sunos5": # use /usr/ccs/bin/dump on solaris - def _get_soname(f): + def _get_elf_field(f, field): if not f: return None cmd = "/usr/ccs/bin/dump -Lpv 2>/dev/null " + f with contextlib.closing(os.popen(cmd)) as f: data = f.read() - res = re.search(r'\[.*\]\sSONAME\s+([^\s]+)', data) + res = re.search(r'\[.*\]\s%s\s+([^\s]+)' % field, data) if not res: return None return res.group(1) + + def _get_soname(f): + return _get_elf_field(f, 'SONAME') + + def _get_rpath(f): + return _get_elf_field(f, 'RPATH') + else: def _get_soname(f): # assuming GNU binutils / ELF @@ -184,7 +191,9 @@ if not paths: return None - for dir in paths.split(":"): + rpath = _get_rpath(sys.executable) + rpath = rpath.split(":") if rpath else [] + for dir in rpath + paths.split(":"): libfile = os.path.join(dir, "lib%s.so" % name) if os.path.exists(libfile): return libfile