[Distutils] Linking to libs on MacOS X

Matthew Smith mps@viewbuild.com
Tue Dec 10 22:00:02 2002


Me again, discovered that I need to specify the library as cryptopp, not
libcryptopp.a (so it now compiles and links except for the i386 warnings).

I've tried to test the module by navigating to the directory containing the
vbsecurity.so file, launching the command line python and typing "import
vbsecurity".

This leads to the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ImportError: Failure linking new module

Any ideas??

Thanks,

Matt

> 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
> 
> 
> _______________________________________________
> Distutils-SIG maillist  -  Distutils-SIG@python.org
> http://mail.python.org/mailman/listinfo/distutils-sig
>