[Distutils] how to build a python extension with a shared object in osx10.11

Nathaniel Smith njs at pobox.com
Thu Jul 27 17:23:18 EDT 2017


Try libraries=["foo"] – this should cause it to pass "-lfoo" to the linker,
and then the linker will convert that into "libfoo.dylib".

On Jul 27, 2017 11:11 AM, "bin" <xiazhibin381 at gmail.com> wrote:

> I have installed libfoo.dylib into /usr/local/lib
>
> And my python extension's setup.py:
>
> from distutils.core import setup, Extension
>
> module1 = Extension('bar',
>                     libraries=['libfoo2.dylib', ],
>                     language="c++",
>                     extra_compile_args=['-v', ],
>                     sources=['main.cpp'])
>
> setup(name='PackageName',
>       version='1.0',
>       description='This is a demo package',
>       ext_modules=[module1])
>
> but it build failed for can not founding the libfoo2.dylib.
>
> Here is complie message:
>
> "/Applications/Xcode.app/Contents/Developer/Toolchains/
> XcodeDefault.xctoolchain/usr/bin/lipo" -create -output
> build/temp.macosx-10.11-intel-2.7/main.o /var/folders/45/
> gz7ljrz94mdct3nvm9l5ftnr0000gp/T/main-684613.o /var/folders/45/
> gz7ljrz94mdct3nvm9l5ftnr0000gp/T/main-94fc36.o
> c++ -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -Wl,-F.
> build/temp.macosx-10.11-intel-2.7/main.o -L/usr/local/lib -llibfoo2.dylib
> -o build/lib.macosx-10.11-intel-2.7/bar.so
> ld: library not found for -llibfoo2.dylib
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> error: command 'c++' failed with exit status 1
>
>
>
> _______________________________________________
> Distutils-SIG maillist  -  Distutils-SIG at python.org
> https://mail.python.org/mailman/listinfo/distutils-sig
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/distutils-sig/attachments/20170727/06bf33fd/attachment.html>


More information about the Distutils-SIG mailing list