在使用带有distutils的python ctypes时如何查找到共享库的路径

2024-10-01 11:21:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个python包,它基本上是c后端的python包装器。c-backend通过ctypes称为formpython。在

如果我给ctypes一个指向库的绝对路径来加载它,它会很好地工作。但是如果库是通过distutils编译的,我不知道如何找到库的绝对路径setup.py?(安装脚本成功地构建了库。)

以下是setup.py的重要片段:

libreboundmodule = Extension('librebound',
                sources = [ 'librebound/librebound.c' ],
                                )

setup(name='rebound',
    ...
    ext_modules = [libreboundmodule])

这是反弹模块的一部分__init__.py。如何让ctypes知道我的库的路径?在

^{pr2}$

编辑:

可以做以下事情吗?在

import ctypes
PATH = os.path.dirname(__file__)
librebound = ctypes.CDLL(PATH+"/../librebound.so", RTLD_GLOBAL)

Tags: pathnamepy脚本backendsetupextensionctypes