8

In OS X Snow Leopard (10.6) I used the following lines in ~/.bashrc to force compilation with clang instead of standard gcc:

# Set Clang as the default compiler for the system
export CC=clang
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments

I also (occasionally) had to use the following lines to use llvm-gcc when clang would fail to compile certain things (PostgreSQL was guilty of this for a long time):

# Set LLVM GCC as the default compiler for the system
export CPP='llvm-gcc-4.2'
export CC='llvm-gcc-4.2'
export CXX='llvm-g++'

On OS X Lion (10.7), are these lines still required? Is llvm-gcc (or clang) the default compiler for the system? Or will these lines still need to live in my ~/.bashrc?

Bryson
  • 1,186
  • 2
  • 13
  • 26

2 Answers2

7

The default compiler on Lion is now llvm-gcc-4.2, although the standard selection (gcc-4.2, llvm-gcc-4.2, clang) remains unchanged from Snow Leopard. Try reading Using the right compiler.

Chris Mowforth
  • 6,689
  • 2
  • 26
  • 36
5

gcc is symlinked to llvm-gcc-4.2 on Lion.

lrwxr-xr-x  1 root  wheel  12 Jul 21 20:51 /usr/bin/gcc -> llvm-gcc-4.2
lrwxr-xr-x  1 root  wheel  12 Jul 21 20:51 /usr/bin/g++ -> llvm-g++-4.2

You can probably remove those environment variables without much harm.

Løiten
  • 3,185
  • 4
  • 24
  • 36
timwoj
  • 388
  • 4
  • 14
  • 3
    For those that don't know, in order to get gcc in /usr/bin you have to install Xcode 4.1 and if you do that from the App Store be sure to select the right Xcode Installer (you might have the 3.x version installer for Snow Leopard). – Bjorn Aug 14 '11 at 06:19
  • 3
    I installed Xcode 4.3.1 from the App Store on Lion and had to go to Preferences->Downloads->Components and install Command Line Tools to get gcc in /usr/bin – Lukasz Wiklendt Mar 14 '12 at 02:26
  • Lukasz - thanks! Just spent about an hour trying to figure out how RVM was giving me this much trouble for a simple install. Command line tools are not installed by default. Fail! – adam reed Jun 18 '12 at 20:52
  • When compiling or installing some python modules, you'll need the older fortan compiler (gfortan) to override the lion (XCode) default. Otherwise the Lion will sneak up on you with insidious math errors in modules like numpy, scipy, and perhaps pandas. And for scipy you may need additional env directives like: CXX=clang++ && FFLAGS=-ff2c for things to go smoothly. – hobs Oct 30 '12 at 20:22