Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Short version: What's the simplest way to use MacPorts' gcc with CreateLibrary?

Long version:

CreateLibrary uses /usr/bin/gcc by default on OS X. I can get it to use clang by using the option "CompilerName" -> "clang++" or "CompilerName" -> "c++" (I'm using C++).

However, I would like to use MacPorts' gcc because it boosts the performance significantly for this particular program I need to compile. "CompilerName" -> "g++-mp-4.7" tells me that

CreateLibrary::instl: The compiler installation directive "CompilerInstallation" -> "/usr/bin" does not indicate a usable installation of "GCC"

So I tried "CompilerInstallation" -> "/opt/local/bin", which is the location of g++-mp-4.7. This results in the same error:

CreateLibrary::instl: The compiler installation directive "CompilerInstallation" -> "/opt/local/bin" does not indicate a usable installation of "GCC"

Is there a simpler solution than using GenericCCompiler?

share|improve this question
    
Check the source code for the CCompilerDriver` package. You might be surprised at how simplistic the checks are for whether a compiler is "usable" or not. No doubt one could arrive at some fairly simple modifications to the package to make it work properly. –  Oleksandr R. Sep 5 '13 at 21:04
    
I get the impression that a driver has to be created to fully use a particular compiler. As already suggested, look at the other drivers in that directory. Now the next question is, once created, how does one integrate the driver into the system? –  rcollyer Sep 5 '13 at 21:09
    
@rcollyer a "driver" just provides the right command line arguments and link libraries. Writing a new one does not seem to be that difficult, although strictly speaking since CCompilerDriver` package is not "supplied as an example" (or so one would suppose), modifying it would contravene the Mathematica licence. –  Oleksandr R. Sep 5 '13 at 21:53
    
@OleksandrR. yes, and more specifically, it tells CCompilerDriver` how to interface with the compiler. So, while there isn't an "example" of how to do it, you could learn how by looking at the packages supplied. –  rcollyer Sep 5 '13 at 23:00
    
Here's a guess: set "Compiler" -> CCompilerDriver`GCCCompiler`GCCCompiler, in addition to "CompilerInstallation" and "CompilerName". –  rcollyer Sep 6 '13 at 3:09
show 3 more comments

1 Answer

up vote 1 down vote accepted

I ended up using the GenericCCompiler driver, as follows:

CreateLibrary[{"mylib.cpp"}, "mylib", 
 "IncludeDirectories" -> "/opt/local/include", 
 "ShellOutputFunction" -> Print, "ShellCommandFunction" -> Print, 
 "Language" -> "C++", 

 "Compiler" -> CCompilerDriver`GenericCCompiler`GenericCCompiler, 
 "CompilerInstallation" -> "/opt/local/bin", 
 "CompilerName" -> "g++-mp-4.7", 
 "CompileOptions" -> "-O3 -m64 -fPIC -lMLi3"]

It is good to note that the "Libraries" and "SystemLibraries" options are not usable on OS X because this driver auto-appends .lib to any library name, which is incorrect on OS X.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.