[C++-sig] can't import Boost.Python Extension OSX 10.4

stephan nies nies.stephan at googlemail.com
Wed Feb 7 00:22:13 CET 2007


SOLVED

the trick is to link the extension module
using the -bundle flag on OS X
but still nameing it extension.so
and not extension.dylib

perhaps it might be a good idea to mention this somewhere
in the documentation since this might not be obvious for
programmers used to Unix or Linux

Thanks go to Torsten Sadowski over at macpython-sig
http://mail.python.org/pipermail/pythonmac-sig/2007-February/018672.html

Also i want to thank the creators of boost.python
for this great Library

Stephan


On 2/1/07, stephan nies <nies.stephan at googlemail.com> wrote:
> Hello,
>
> i am porting an app from linux to osx which uses
> bost.python - extension module
>
> Machine: 2 GHz PowerPC G5
> OS:        Mac OS X 10.4.8
> Python:   python-2.4.4-macosx2006-10-18.dmg
>               from http://pythonmac.org/packages/py24-fat/dmg/
>               (this is a framework build)
> Boost:    1.33.1 build from source (./configure && make)
>
> i am building my extension by invoking:
>
> g++ -dynamic myextension.cpp
> -I/Library/Frameworks/Python.framework/Headers
> -I/System/Library/Frameworks/GLUT.framework/Headers -I/usr/include
> -I/Users/nies/src/boost_1_33_1 -c -o myextension.o
>
> and
>
> g++ -v -dynamiclib -framework Python -framework OpenGL -framework GLUT
> -L/Users/nies/src/boost_1_33_1/bin/boost/libs/python/build/libboost_python.dylib/darwin/release/shared-linkable-true/
> -lboost_python-1_33_1 myextension.o -o myextension.dylib
>
> this compiles and when i try to import the extension in pythonw:
>
> Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import myextension
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ImportError: No module named myextension
>
> as far as i understand this is because python searches for
> .so files.  when i symbolic-link  myextension.so -> myextension.dylib
> and than try to import:
>
> Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import myextension
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> ImportError: Inappropriate file type for dynamic loading
>
> so what am i doing wrong here? i searched around now quite some
> time but didn't find anything but the .dylib to .so renaming. I would really
> appreciate some hints at this point.
>
> Thanks,
> Stephan
>



More information about the Cplusplus-sig mailing list