clib.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:cwrap 作者: Statoil 项目源码 文件源码
def load( lib, so_version = None, path = None, so_ext = None):
    """Thin wrapper around the ctypes.CDLL function for loading shared
    library.

    If the path argument is non Null the function will first try to
    load with full path. If that fails it wil also try to load without
    a path component, invoking normal dlopen() semantics.
    """

    dll = None
    lib_files = [ lib_name( lib, path = None, so_version = so_version ),
                  lib_name( lib, path = None, so_version = so_version, so_ext = so_ext ),
                  lib_name( lib, path = path, so_version = so_version ),
                  lib_name( lib, path = path, so_version = so_version, so_ext = so_ext )
                ]

    for lib_file in lib_files:
        try:
            dll = ctypes.CDLL(lib_file , ctypes.RTLD_GLOBAL)
            return dll
        except Exception as exc:
            error = exc

    error_msg = "\nFailed to load shared library:%s\n\ndlopen() error: %s\n" % (lib , error)

    LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH")
    if not LD_LIBRARY_PATH:
        LD_LIBRARY_PATH = ""

    error_msg += """
The runtime linker has searched through the default location of shared
libraries, and also the locations mentioned in your LD_LIBRARY_PATH
variable. Your current LD_LIBRARY_PATH setting is:

   LD_LIBRARY_PATH: %s

You might need to update this variable?
""" % LD_LIBRARY_PATH
    raise ImportError(error_msg)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号