2

TLDR: I want to use the llvm compiler, not some other gcc compiler that I installed using macports.

Whilst trying to compile a c++ library, I ran into this error:

c++: error: unrecognized option '-arch'

After searching on SO, I found this post post which indicates that the '-arch' option is part of Apple's extensions to gcc.

A while ago I installed a different GCC version, using Macports, in order to compile some tools for some other software. Now when I check this, I can confirm that it is using the version from Macports:

$ g++ --version
g++ (MacPorts gcc46 4.6.4_3) 4.6.4
$ which g++ --version
/opt/local/bin/g++

Using port select only yields two options,

$ port select --list gcc
Available versions for gcc:
    mp-gcc46 (active)
    none

So I can't change the default compiler here. Where can I change this to use the llvm compiler in /usr/bin/?

Community
  • 1
  • 1
JessMcintosh
  • 460
  • 2
  • 6
  • 21

3 Answers3

2

The compiler that comes with LLVM is Clang, not GCC. Have you got XCode 5 installed? And the command line tools as well? This post explains how to install them quite clearly.

Then you can try to run clang --version to verify that clang has been installed properly and is available in the command line. Then to compile with auto-tools, you can pass it in the CC and CXX variables as @paul-roub said:

CC=clang CXX=clang++ ./configure
make

Bear in mind that Apple is using a modified version of LLVM/Clang. They used to use GCC before but they dropped the support for it when the license changed to GPLv3 if I remember correctly. On a clean 10.9 install with XCode 5.1 you shouldn't have GCC at all though, it's been completely replaced by Clang.

Community
  • 1
  • 1
Uflex
  • 1,396
  • 1
  • 13
  • 32
1

Configure scripts and Makefiles will often respect the CC and CXX environment variables, telling them to use a specific compiler.

e.g.:

$ CXX=/usr/bin/g++ CC=/usr/bin/gcc ./configure
$ CXX=/usr/bin/g++ CC=/usr/bin/gcc make
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
  • Is there a way to make this a permanent change? I'm also trying to install something using `python setup.py install` and not a makefile . – JessMcintosh Apr 02 '14 at 14:16
  • You can add `export CXX=/usr/bin/g++`, etc. to your `.Profile`, but that may mess up other things. I'd hope the Python setup tools would also respect these variables, but haven't tried. – Paul Roub Apr 02 '14 at 14:44
1

I believe you need to select none to go back to the default compiler. If no gcc compiler is selected using macports (and therefore, no link called gcc exists in /opt/bin) then the first gcc compiler encountered will be the one in /usr/bin.

Vortexfive
  • 1,889
  • 13
  • 19