Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default compiler for linking C code in Python package

I'm trying to compile a Python package which has some Cython-generated C code, and I'm running into:

gcc: error: x86_64: No such file or directory

which indicates that the gcc compiler is too recent, so doesn't support -arch anymore. I tried setting CC=/usr/bin/gcc prior to python setup.py install, and this works for the main compile command, but not for the command to make the shared object library:

% setenv CC /usr/bin/gcc
% python setup.py install
running install
running build
running build_py
running build_ext
skipping 'hyperion/util/integrate_core.c' Cython extension (up-to-date)
building 'hyperion.util.integrate_core' extension
/usr/bin/gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -DNDEBUG -g -O3 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -I/Library/Frameworks/EPD64.framework/Versions/7.2/lib/python2.7/site-packages/numpy/core/include -I/Library/Frameworks/EPD64.framework/Versions/7.2/include/python2.7 -c hyperion/util/integrate_core.c -o build/temp.macosx-10.5-x86_64-2.7/hyperion/util/integrate_core.o
gcc -bundle -undefined dynamic_lookup -g -arch x86_64 -arch x86_64 build/temp.macosx-10.5-x86_64-2.7/hyperion/util/integrate_core.o -o build/lib.macosx-10.5-x86_64-2.7/hyperion/util/integrate_core.so

gcc: error: x86_64: No such file or directory
gcc: error: x86_64: No such file or directory
gcc: error: unrecognized option ‘-arch’
gcc: error: unrecognized option ‘-arch’
error: command 'gcc' failed with exit status 1

Is there a way to specify the absolute path of the compiler to use for linking?

like image 547
astrofrog Avatar asked Mar 15 '26 06:03

astrofrog


1 Answers

Use LDSHARED variable: LDSHARED='/usr/bin/gcc -shared'.

It's buried in sysconfig module. Try this:

>>> from sysconfig import get_config_vars
>>> get_config_vars('CC', 'CXX', 'LDSHARED')
like image 131
klimkin Avatar answered Mar 17 '26 21:03

klimkin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!