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. It also supports OpenMP; the system compiler doesn't. "CompilerName" -> "g++-mp-5"
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-5
. 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?
Answer
I ended up using the GenericCCompiler
driver, as follows:
$CCompiler = {
"Compiler" -> CCompilerDriver`GenericCCompiler`GenericCCompiler,
"CompilerInstallation" -> "/opt/local/bin",
"CompilerName" -> "g++-mp-5",
"SystemCompileOptions" -> "-O2 -m64 -fPIC -framework Foundation -framework mathlink"
};
The compiler definition should use "SystemCompileOptions"
instead of "CompileOptions"
so that the user can set their own custom "CompileOptions"
when desired.
CreateLibrary[{"mylib.cpp"}, "mylib",
"IncludeDirectories" -> "/opt/local/include",
"ShellOutputFunction" -> Print, "ShellCommandFunction" -> Print,
"Language" -> "C++"]
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.
Comments
Post a Comment