Distutils setup generate .so and not .dylib on Mac OS X

时光毁灭记忆、已成空白 提交于 2020-07-19 07:03:05

问题


I've been trying to create C bindings for a Python library following an official tutorial presented by the developer of the latter library using Cython (https://www.ibisc.univ-evry.fr/~fpommereau/SNAKES/snakes-out-of-python.html).

The cythonization of the library works perfectly. However, when calling the creation of the library file with distutils.core.setup on Mac OS X 10.10.5, it produces a file .so. However, when I need to compile the example .c file with the library, I end up having the following error message:

ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) file './libsnk.so' for architecture x86_64

I've looking through the documentation of distutils.core.setup to see if there was any way to specify the type of file generated (in my case .dylib), unsuccessfully.

I've tried to follow the tutorial using a virtual machine running Ubuntu 14.04.3 and I was able to make it work easily.

Is there a way to overcome this problem? Is there a way to specify to distutils.core.setup that it must generate a file with the .dylib format? Is there a way to make it work with distutils.core.setup still generating a file with the .so format?

Thank you for your answers


回答1:


I'm trying to do something similar, for me this answer helped: How to create a .dylib C extension on mac os x with distutils and/or setuptools?

The key code fragment was:

if sys.platform == 'darwin':
    from distutils import sysconfig
    vars = sysconfig.get_config_vars()
    vars['LDSHARED'] = vars['LDSHARED'].replace('-bundle', '-dynamiclib')

Added to setup.py



来源:https://stackoverflow.com/questions/32757007/distutils-setup-generate-so-and-not-dylib-on-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!