Message Boards Message Boards

0
|
3666 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

CCompilerDriver: How can I use different versions of clang or gcc on OS X?

Posted 9 years ago

I am using LibraryLink and CCompilerDriver on OS X. I would like to use a different compiler than the system's default. For example, I can install different versions of clang and gcc using MacPorts. Using gcc is necessary if I want OpenMP.

CCompilerDriver comes with a clang driver and a gcc driver. Both work with the system defaults. But how can I coerce them to work with a compiler having a different name (in the case of MacPorts, gcc might be named gcc-mp-5) and installed in a different location (e.g. /opt/local/bin)? However, I am unable to use either (CCompilerDriver`ClangCompiler`ClangCompiler or CCompilerDriver`GCCCompiler`GCCCompiler) with a different installation of gcc or clang.

I can set up CCompilerDriver`GenericCCompiler`GenericCCompiler to sort of work, with something like this:

$CCompiler = {"Compiler" -> CCompilerDriver`GenericCCompiler`GenericCCompiler, 
    "SystemCompileOptions" -> "-m64 -fPIC -O2 -framework Foundation", "CompilerName" -> "g++-mp-5", 
    "CompilerInstallation" -> "/opt/local/bin"};

But this has its own problems because it's geared towards Windows. For example "Libraries" -> {"foo"} will translate to the compiler option -lfoo.lib instead of -lfoo, and won't work on OS X. Then I have to resort to some ugly hack such as passing -lfoo in "CompilerOptions", which then brings its own problems and inconveniences.

So, short of trying to write a compiler drivers (which looks very daunting and I won't try), how can I use a non-default gcc or a non-default clang on OS X?

POSTED BY: Szabolcs Horvát
3 Replies

Yes, it is a bug: the code that checks for compiler existence takes into account only "CompilerInstallation" but not "CompilerName". Thank you for pointing this out.

POSTED BY: Ilian Gachevski

This seems to do something reasonable for me

 $CCompiler = {"Compiler" -> CCompilerDriver`GCCCompiler`GCCCompiler, 
   "CompilerInstallation" -> "/usr/local/bin/gcc-4.9"}

where gcc-4.9 is the actual compiler executable, not the directory containing it.

POSTED BY: Ilian Gachevski

Thank you, this works!

But what is the "CompilerName" option for then? Is there an inconsistency between different drivers in how "CompilerName" and "CompilerInstallation" are used?

POSTED BY: Szabolcs Horvát
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract