[Pyrex] problems Linking under Mac OSX

Bob Ippolito bob at redivi.com
Fri Oct 10 05:50:20 CEST 2003


On Oct 9, 2003, at 19:27, Greg Ewing wrote:

> David McNab <david at rebirthing.co.nz>:
>
>> To anyone who's conversant with Mac OSX, can you please tell me:
>> 1) What's the proper way to locate the needed libcrypto.so and
>> libpython2.x.so (or equivalent) files on OSX?
>
> On the MacOSX 10.1 system I have beside me at the moment,
> there's a libcrypto.dylib in /usr/lib, so I don't see why
> -lcrypto shouldn't work for that (and a brief experiment
> confirms that it does).
>
> As for Python, it will depend on whether it was compiled
> and installed in the traditional Unix fashion, or whether
> it was installed as a framework. If the latter, you will
> need
>
>   -framework Python
>
> That should be enough if the framework is in one of the
> standard locations, such as /Library/Frameworks.

Or /System/Library/Frameworks, in the case of 10.3 ..  But for 10.2, 
with their broken Python 2.2.0, you need to use either "-bundle_loader 
/usr/bin/python" or "-undefined suppress -flat_namespace" in addition 
to your -bundle suggestion below.  But please, for god's sake, please 
please don't support Apple's broken Python 2.2.0.  Nothing you do for 
2.2.0 will work with OS X 10.3, anyways.. but stuff you compile for 
MacPython 2.3 (which runs on 10.2 and later) will also work with the 
system installed Python 2.3 with OS X 10.3.

>> 2) Given my Pyrex-generated file 'SSLCrypto.c', which has compiled ok
>> into 'SSLCrypto.o', what gcc options should I use to link it into a
>> module that can be imported into Python?
>
> To create an extension module, you will also need
>
>   -bundle
>
> e.g.
>
>   cc -bundle -framework Python mymodule.o -o mymodule.so
>
> At least I think that's all you need, but I may have
> forgotten some vital thing.
>
> But the best way to compile extension modules is probably to use
> distutils, which knows all the tricky details of how to do it right
> for your particular system and installation.  I'd recommend writing a
> setup.py for your module. You can invoke it from the makefile if you
> want people to be able to use make.

Yes, distutils is the way.  Distutils knows what flags to use for any 
given Python.  If you have 8 versions of Python on your computer, 
distutils knows exactly which cc/ldflags to use for the version of 
Python you invoked it with.  Compiling modules yourself, without 
distutils,  is just asking for pain.

-bob





More information about the Pyrex mailing list