[Distutils] Linking to libs on MacOS X

Matthew Smith mps@viewbuild.com
Tue Dec 10 21:36:03 2002


Hello,

I'm having some difficulty extending python with a .cpp file and a library
on Mac OS X 10.2.2 (I can't get distutils to find the library).

The extention file (vbsecurity.cpp) file contains my the functions I am
trying to make available to python, which needs to link to my library:
libcryptopp.a (it's in the root of my distribution directory with the
headers in a subdirectory - crypto42).

The vbsecurity.cpp also makes use of a class (aesphm.cpp, aesphm.h).

Now my setup.py file looks like the following:



#!/usr/bin/env python

from distutils.core import setup, Extension

module1 = Extension('vbsecurity',
                    sources = ['vbsecurity.cpp'],
                    include_dirs=['crypto42'],
                    #library_dirs=[''],
                    libraries=['libcryptopp.a'])

setup (name = 'vbsecurity', version = '1.0', ext_modules = [module1])


I've tried using library_dirs with an absolute path, placing the lib in a
subdirectory and using a relative path, as well as placing the lib in
'/usr/lib/'.



And I get the following output:



mps% python setup.py build
running build
running build_ext
building 'vbsecurity' extension
creating build
creating build/temp.darwin-6.2-Power Macintosh-2.2
gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -no-cpp-precomp -Icrypto42
-I/usr/include/python2.2 -c vbsecurity.cpp -o build/temp.darwin-6.2-Power
Macintosh-2.2/vbsecurity.o

    [snip - some warnings]

creating build/lib.darwin-6.2-Power Macintosh-2.2
gcc -arch i386 -arch ppc -bundle -flat_namespace -undefined suppress
build/temp.darwin-6.2-Power Macintosh-2.2/vbsecurity.o -llibcryptopp.a -o
build/lib.darwin-6.2-Power Macintosh-2.2/vbsecurity.so
ld: for architecture i386
ld: warning /usr/lib/bundle1.o cputype (18, architecture ppc) does not match
cputype (7) for specified -arch flag: i386 (file not loaded)
ld: warning build/temp.darwin-6.2-Power Macintosh-2.2/vbsecurity.o cputype
(18, architecture ppc) does not match cputype (7) for specified -arch flag:
i386 (file not loaded)
ld: can't locate file for: -llibcryptopp.a
error: command 'gcc' failed with exit status 1



No matter what I've tried, I can't get it to find the library.

Any help would be great...

Cheers

Matt