7

I'm trying to cross-compile the pycrypto package, and I'm getting closer and closer however, I've hit an issue I just can't figure out.

I want distutils to use the cross-compile specific gcc- so I set the CC env var and it seems to respect the setting for the first invocation of the compiler, but thats it.

export CC="/opt/teeos/buildroot/output/host/usr/bin/i586-linux-gcc"
/opt/teeos/buildroot/output/host/usr/bin/i586-linux-gcc -fno-strict-aliasing -fwrapv -Wall -Wstrict-prototypes -fPIC -std=c99 --sysroot=/opt/teeos/buildroot/output/staging -I/opt/teeos/buildroot/output/staging/usr/include/python2.7 -O3 -fomit-frame-pointer -Isrc/ -I/usr/include/python2.7 -c src/_fastmath.c -o build/temp.linux-i686-2.7/src/_fastmath.o
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions build/temp.linux-i686-2.7/src/_fastmath.o -lgmp -o build/lib.linux-i686-2.7/Crypto/PublicKey/_fastmath.so
unable to execute gcc: No such file or directory

I temporarily moved my systems gcc so it can't be found.

How do I make distutils respect the CC=/opt/buildroot... option for every invocation of the compiler / set the path to the GCC / LD I want distutils to use?

tMC
  • 18,105
  • 14
  • 62
  • 98

1 Answers1

16

This sounds similar to another answer I recently gave for customizing the distutils compiler. You'll also need to define LDSHARED which is the command used to produce the final shared object. See if this works:

>>> from distutils import sysconfig
>>> sysconfig.get_config_var('LDSHARED')
'gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
>>> sysconfig.get_config_var('CC')
'gcc -pthread'

Then replace gcc with your desired compiler and options in the CC and LDSHARED environment variables:

% LDSHARED="i586-linux-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions" \
  CC="i586-linux-gcc -pthread" python setup.py build
Community
  • 1
  • 1
samplebias
  • 37,113
  • 6
  • 107
  • 103
  • I'm rebuilding my tool-chain right now- I've been messing with it alot and want a clean base; i'll try this as soon as its done. This looks perfect! I read the distutils docs and googled everything i could think of- where did you find this? – tMC May 13 '11 at 02:53
  • Cool, I hope it helps. I found it by digging through the guts of distutils, which I've done several times tackling related matters (customizing compiler options and the like). – samplebias May 13 '11 at 03:26
  • that did it... but now my tool chain is linking against the wrong libs. that never happened before- but thats a different issue. damn thing. thanks! – tMC May 13 '11 at 04:31