D. Lawrence
D. Lawrence

Reputation: 949

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

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

Upvotes: 2

Views: 1188

Answers (1)

chromy
chromy

Reputation: 162

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

Upvotes: 2

Related Questions