8

I'm trying to get setup.py to compile c++ code with the macports version of gcc. The problem is the code I am trying to build, doesn't support mac's default clang, which is the default gcc on newer osx versions.

I created a custom setup.cfg file

setup.cfg

[build_ext] 
compiler=gcc-mp-4.8

However when I run python setup.py build_ext I get the following error

running build_ext

error: don't know how to compile C/C++ code on platform 'posix' with 'gcc-mp-4.8' compiler

How can I get setup.py to use my version of gcc gcc-mp-4.8?

Currently setup.py defaults to using /usr/bin/clang, when i type gcc -v it shows that it is using gcc version 4.8.2

pyCthon
  • 11,746
  • 20
  • 73
  • 135
  • Have you tried using the absolute path to your gcc-mp-4.8? – l'L'l Aug 31 '14 at 18:42
  • @l'L'l still gives an error , `error: don't know how to compile C/C++ code on platform 'posix' with '/opt/local/bin/gcc-mp-4.8' compiler` – pyCthon Aug 31 '14 at 18:44
  • You could also try setting the macports gcc in your path so it defaults to that version; It seems as if it's still looking at clang. – l'L'l Aug 31 '14 at 18:48
  • @l'L'l the question is how, I added more information above as well. – pyCthon Aug 31 '14 at 18:57

1 Answers1

11

The --compiler option expects "unix", "msvc", "cygwin", "mingw32", "bcpp", or "emx", from my understanding. You can try setting the compiler name by specifying a CC environment variable instead.

Inside setup.py try setting os.environ:

os.environ["CC"] = "gcc-4.8"
os.environ["CXX"] = "gcc-4.8"

or just:

CC=gcc

g++ would be used like this too;

os.environ["CXX"] = "g++-4.7"
l'L'l
  • 44,951
  • 10
  • 95
  • 146