用distutils编译C共享库设置.py,当库依赖于第二个共享库时

2024-09-29 21:35:54 发布

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

我在OSX上,试图用distutils用C编译一个共享库设置.py(在python中使用ctypes)。我不熟悉distutils,但我在编译共享库时遇到了问题(Libbanex公司)依赖于另一个共享库(伦敦银行反弹). 显然,在modify_orbits_direct.c中

#include "rebound.h"

h在目录/Users/dt/breadbound/src/中,bound.h中的所有函数都在共享库中伦敦银行反弹,位于/Users/dt/breadbound/中。在

与cc的链接看起来像。在

^{pr2}$

更新:这种情况与Sec末尾的示例完全相同。3在https://docs.python.org/2/extending/building.html。我更新了我的设置.py为了模仿这个:

libreboundxmodule = Extension('libreboundx',
                sources = [ 'src/reboundx.c',
                            'src/modify_orbits_direct.c'],  
                include_dirs = ['src', '/Users/dt/rebound/src'], 
                extra_compile_args=['-fstrict-aliasing', '-O3','-std=c99','-march=native', '-D_GNU_SOURCE', '-fPIC'],
                library_dirs=['/Users/dt/rebound'],
                libraries=['rebound'],
                                )   

当我运行时,这个安装很好

pip install -e ./

生成输出:

You are using pip version 7.0.3, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Obtaining file:///Users/dtamayo/Documents/workspace/reboundx
Installing collected packages: reboundx
Running setup.py develop for reboundx
Successfully installed reboundx-1.0

但当我试着

import reboundx

在Python中,我得到一个OSError:dlopen(Libbanex公司,10):未找到符号:_reb_boundary_particle_is_in_box,它是另一个库中的函数(伦敦银行反弹),甚至在代码中都没有调用Libbanex公司. 在

如果我用上面的cc命令链接共享库,一切正常,我可以使用共享库Libbanex公司C很好。如果我试着用同样的方法Libbanex公司我用cc命令编译并将其粘贴在设置.py会说,然后尝试在python中导入bomberx,我反而得到

OSError: dlopen(/Users/dtamayo/Documents/workspace/reboundx/reboundx/../libreboundx.so, 10): Library not loaded: librebound.so

引用自:/Users/dtamayo/Documents/workspace/bobblex/Libbanex公司 原因:找不到图像

这会像rpath问题,在运行时在哪里Libbanex公司不知道去哪里找libbreback.so?在


Tags: pippysrcsodt公司银行users
1条回答
网友
1楼 · 发布于 2024-09-29 21:35:54

谢谢你的建议。我应该在问题中说明,最终我需要一个解决方案,可以打包上传到PyPy,这样用户就可以用一个命令进行安装。它也应该同时运行在OSX和Linux上,所以我更喜欢不涉及install_name_工具的解决方案。在

我还没能测试它,但我想

 runtime_library_dirs=['/Users/dt/rebound'],

在library-dirs旁边应该可以修复Linux上的问题。显然,这在Mac上不起作用,但您可以使用额外的“链接”参数。在上面发布的libbounderxmodule定义下面添加这个代码

^{pr2}$

解决了我的问题。我在这里找到了答案:Python runtime_library_dirs doesn't work on Mac

相关问题 更多 >

    热门问题