Ejemplo n.º 1
0
 def find_library(name):
     possible = ['lib%s.dylib' % name, '%s.dylib' % name, '%s.framework/%s' % (name, name)]
     for name in possible:
         try:
             return _dyld_find(name)
         except ValueError:
             continue
Ejemplo n.º 2
0
 def find_library(name):
     possible = ["lib%s.dylib" % name, "%s.dylib" % name, "%s.framework/%s" % (name, name)]
     for name in possible:
         try:
             return _dyld_find(name)
         except ValueError:
             continue
     return None
Ejemplo n.º 3
0
 def find_library(name):
     possible = ['lib%s.dylib' % name,
                 '%s.dylib' % name,
                 '%s.framework/%s' % (name, name)]
     for name in possible:
         try:
             return _dyld_find(name)
         except ValueError:
             continue
     return None
Ejemplo n.º 4
0
    def find_library(name):
        from ctypes.macholib.dyld import dyld_find as _dyld_find

        possible = ["lib%s.dylib" % name, "%s.dylib" % name, "%s.framework/%s" % (name, name)]
        for name in possible:
            try:
                return _dyld_find(name)
            except ValueError:
                continue
        return None
Ejemplo n.º 5
0
 def find_library(name):
     possible = ['@executable_path/../lib/lib%s.dylib' % name,
                 'lib%s.dylib' % name,
                 '%s.dylib' % name,
                 '%s.framework/%s' % (name, name)]
     for name in possible:
         try:
             return _dyld_find(name)
         except ValueError:
             continue
     return None
Ejemplo n.º 6
0
 def find_library(name):
     from ctypes.macholib.dyld import dyld_find as _dyld_find
     possible = ['lib%s.dylib' % name,
                 '%s.dylib' % name,
                 '%s.framework/%s' % (name, name)]
     for name in possible:
         try:
             return _dyld_find(name)
         except ValueError:
             continue
     return None
Ejemplo n.º 7
0
 def find_library(name):
     possible = ['lib%s.dylib' % name,
                 '%s.dylib' % name,
                 '%s.framework/%s' % (name, name)]
     # iOS addition: also search for pythonA-math.framework/pythonA-math and lib.framework/lib
     if (os.uname().machine.startswith('iP')):
         pythonName = sys._base_executable
         home, tail = os.path.split(sys.prefix)
         possible.append('%s/Frameworks/%s-%s.framework/%s-%s' % (home, pythonName, name, pythonName, name))
         possible.append('%s/Frameworks/%s.framework/%s' % (home, name, name))
         possible.append('%s/Frameworks/lib%s.framework/lib%s' % (home, name, name))
     for name in possible:
         try:
             return _dyld_find(name)
         except ValueError:
             continue
     return None
Ejemplo n.º 8
0
def find_lib_path(name):
    """
    Find full path of a shared library.

    Searches for the full path of a shared library. On Posix operating systems 
    other than MacOS, this function checks the directories listed in 
    LD_LIBRARY_PATH (if any) and in the ld.so cache. 

    Parameter
    ---------
    name : str
        Link name of library, e.g., cublas for libcublas.so.*.

    Returns
    -------
    path : str
        Full path to library.

    Notes
    -----
    Code adapted from ctypes.util module. Doesn't check whether the
    architectures of libraries found in LD_LIBRARY_PATH directories conform
    to that of the machine.
    """

    if sys.platform == 'win32':
        return ctypes.util.find_library(name)

    # MacOS has no ldconfig:
    if sys.platform == 'darwin':
        from ctypes.macholib.dyld import dyld_find as _dyld_find
        possible = ['lib%s.dylib' % name,
                    '%s.dylib' % name,
                    '%s.framework/%s' % (name, name)]
        for name in possible:
            try:
                return _dyld_find(name)
            except ValueError:
                continue
        return None

    # First, check the directories in LD_LIBRARY_PATH:
    expr = r'\s+(lib%s\.[^\s]+)\s+\-\>' % re.escape(name)
    for dir_path in filter(len,
            os.environ.get('LD_LIBRARY_PATH', '').split(':')):
        f = os.popen('/sbin/ldconfig -Nnv %s 2>/dev/null' % dir_path)
        try:
            data = f.read()
        finally:
            f.close()
        res = re.search(expr, data)
        if res:
            return os.path.join(dir_path, res.group(1))

    # Next, check the ld.so cache:
    uname = os.uname()[4]
    if uname.startswith("arm"):
        uname = "arm"
    if struct.calcsize('l') == 4:
        machine = uname + '-32'
    else:
        machine = uname + '-64'
    mach_map = {
        'x86_64-64': 'libc6,x86-64',
        'ppc64-64': 'libc6,64bit',
        'sparc64-64': 'libc6,64bit',
        's390x-64': 'libc6,64bit',
        'ia64-64': 'libc6,IA-64',
        'arm-32': 'libc6(,hard-float)?',
        }
    abi_type = mach_map.get(machine, 'libc6')
    expr = r'\s+lib%s\.[^\s]+\s+\(%s.*\=\>\s(.+)' % (re.escape(name), abi_type)
    f = os.popen('/sbin/ldconfig -p 2>/dev/null')
    try:
        data = f.read()
    finally:
        f.close()
    res = re.search(expr, data)
    if not res:
        return None
    return res.group(1)
Ejemplo n.º 9
0
def find_lib_path(name):
    """
    Find full path of a shared library.

    Searches for the full path of a shared library. On MacOSX and Posix
    operating systems, this function checks the directories listed in 
    LD_LIBRARY_PATH (if any) and in the ld.so cache. 

    Parameter
    ---------
    name : str
        Link name of library, e.g., cublas for libcublas.so.*.

    Returns
    -------
    path : str
        Full path to library.

    Notes
    -----
    Code adapted from ctypes.util module. Doesn't check whether the
    architectures of libraries found in LD_LIBRARY_PATH directories conform
    to that of the machine.
    """

    if sys.platform == 'win32':
        return ctypes.util.find_library(name)

    # OSX has no ldconfig:
    if sys.platform == 'darwin':
        from ctypes.macholib.dyld import dyld_find as _dyld_find
        possible = ['lib%s.dylib' % name,
                    '%s.dylib' % name,
                    '%s.framework/%s' % (name, name)]
        for name in possible:
            try:
                return _dyld_find(name)
            except ValueError:
                continue
        return None

    # First, check the directories in LD_LIBRARY_PATH:
    expr = r'\s+(lib%s\.[^\s]+)\s+\-\>' % re.escape(name)
    for dir_path in filter(len,
            os.environ.get('LD_LIBRARY_PATH', '').split(':')):
        f = os.popen('/sbin/ldconfig -Nnv %s 2>/dev/null' % dir_path)
        try:
            data = f.read()
        finally:
            f.close()
        res = re.search(expr, data)
        if res:
            return os.path.join(dir_path, res.group(1))

    # Next, check the ld.so cache:
    uname = os.uname()[4]
    if uname.startswith("arm"):
        uname = "arm"
    if struct.calcsize('l') == 4:
        machine = uname + '-32'
    else:
        machine = uname + '-64'
    mach_map = {
        'x86_64-64': 'libc6,x86-64',
        'ppc64-64': 'libc6,64bit',
        'sparc64-64': 'libc6,64bit',
        's390x-64': 'libc6,64bit',
        'ia64-64': 'libc6,IA-64',
        'arm-32': 'libc6(,hard-float)?',
        }
    abi_type = mach_map.get(machine, 'libc6')
    expr = r'\s+lib%s\.[^\s]+\s+\(%s.*\=\>\s(.+)' % (re.escape(name), abi_type)
    f = os.popen('/sbin/ldconfig -p 2>/dev/null')
    try:
        data = f.read()
    finally:
        f.close()
    res = re.search(expr, data)
    if not res:
        return None
    return res.group(1)