How to set C++ compiler outside Macports?

Ryan Schmidt ryandesign at
Sun Jul 29 09:54:07 PDT 2012

On Jul 29, 2012, at 01:35, Ian Wadham < at> wrote:

> On 29/07/2012, at 3:43 PM, Jeremy Huddleston Sequoia wrote:
>> On Jul 28, 2012, at 21:35, Ian Wadham < at> wrote:
>>> In my Mac OS X environment, /usr/bin/c++ is a symbolic link to
>>> llvm-g++-4.2, but I need it to be to the same compiler as Macports
>>> used to build kdelibs4.  Then I can compile and link my own code
>>> correctly with that library and continue developing and testing my
>>> source code for the next release of KDE.
>> Why are you using /usr/bin/c++?  Just use /usr/bin/clang++ (or 'xcrun clang++' if you didn't install the command line tools).
> It's not that simple.  I never use a compiler directly, just CMake initially,
> including all the KDE macros and dependencies, then "make" on later
> runs.  CMake picks up /usr/bin/c++, by default, but could no doubt be
> made to do something else.

Probably the usual CC and CXX environment variables could be used to influence that.

>>> For the moment, I have found that "brute force" linking of /usr/bin/c++
>>> to clang works fine, but is there a safer way?  Is there, for example,
>>> some way (e.g. a script or command) to extract from Macports the
>>> compiler it used and make it a symbol in my own builds?
>> You can look at the build logs to see what compiler is used, but on anything recent will be using clang.
> By default, Macports does not leave logs behind.

If you like, you can set "keeplogs yes" in macports.conf to change that.

> I was looking perhaps for
> some Macports cache or config file where compiler assignments are kept
> for each port or for ports in general, but have been unable to find any.

The source code that decides which compiler to use is here:

It's not terribly straightforward and not something you can just grep out of it.

> Is use of clang now official Macports policy?  Last I heard on this list, a
> few months back, its use was experimental.

The compiler MacPorts uses by default is chosen based on the Xcode version.

Xcode 2.x: gcc-4.0
Xcode 3.x: gcc-4.2
Xcode 4.0 and 4.1: llvm-gcc-4.2
Xcode 4.2 and up: clang

Individual ports might override that choice if necessary by setting configure.compiler or compiler.blacklist or compiler.whitelist.

More information about the macports-users mailing list