Choose your clang compiler on OS X ( use Macports)

In Mathematica’s LibraryLink package and CCompilerDriver package, you have the option to choose a specific compiler. This would enable you to use future release of gcc/intel/llvm for test or the legacy version for compatibility. Here is an quick example:

On my OS X 10.11.2, I have a default clang at /usr/local/bin and several other compilers from Macports.

To use any of them in Mathematica, I can load this package first:

Needs["CCompilerDriver`"]

The default setting of the compiler list is

CCompilers[Full] // TableForm

I can set the global keyword $CCompiler with the following value:

$CCompiler = {"Name" -> "Clang", 
  "Compiler" -> CCompilerDriver`ClangCompiler`ClangCompiler, 
  "CompilerInstallation" -> "/opt/local/bin/clang-mp-3.6", 
  "CompilerName" -> Automatic}; 

I use this simple example from the documentation of CreateExecutable plus "ShellCommandFunction" -> Print so that I can see the cascaded build command. Use the Import["!"] to pass result back to front end with unix pipe: