What options can be used for compilation using Compile or CreateExecutable in Mathematica and where can one find details on the possible values for the settings?
I have a recent build of MinGW installed on a Win7 workstation which works when called from the command line, but it isn't detected by Mathematica. The following should let Mathematica know where to find the compiler:
Needs["CCompilerDriver`GenericCCompiler`"]
$CCompiler = {"Compiler" -> GenericCCompiler, "CompilerInstallation" -> "C:\\Program Files\\mingw-builds\\x64-4.8.1-posix-seh-rev5\\mingw64\\bin","CompilerName" -> "x86_64-w64-mingw32-gcc.exe","CompileOptions" -> "-O2"};
Why does the following test code (from the specific compilers help) fail to compile? I assume Mathematica is still not recognizing the C compiler, but it's not clear why.
In[1]:= greeter = CreateExecutable[StringJoin[
"#include<stdio.h>\n",
"int main(){\n",
" printf(\"Hello MinGW-w64 world.\\n\");\n",
"}\n"],
"hiworld", "Compiler" -> GenericCCompiler,
"CompilerInstallation" ->
"C:\\Program Files\\mingw-builds\\x64-4.8.1-posix-seh-rev5\\mingw64\\bin",
"CompilerName" -> "x86_64-w64-mingw32-gcc.exe"]
Out[1]= $Failed
Setting the "Debug"->True for CreateExecutable gives us some additional output:
In[2]:= greeter = (*same as above, with "Debug"->True*)
C:\Users\myusername\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-mycomputer-1000-1000-1>C:\Program Files\mingw-builds\x64-4.8.1-posix-seh-rev5\mingw64\bin\x86_64-w64-mingw32-gcc.exe -o
"C:\Users\myusername\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-mycomputer-1000-1000-1\hiworld.exe"
-g -I"C:\Program Files\Wolfram Research\Mathematica\10.0\SystemFiles\IncludeFiles\C" -I"C:\Program Files\Wolfram Research\Mathematica\10.0\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\include"
"C:\Users\myusername\AppData\Roaming\Mathematica\SystemFiles\LibraryResources\Windows-x86-64\Working-mycomputer-1000-1000-1\hiworld.c"
-L"C:\Program Files\Wolfram Research\Mathematica\10.0\SystemFiles\Links\MathLink\DeveloperKit\Windows-x86-64\CompilerAdditions\mldev64\lib"
-L"C:\Program Files\Wolfram Research\Mathematica\10 .0\SystemFiles\Libraries\Windows-x86-64" 2>&1
C:\Program is not recognized as an internal or external command, operable program or batch file.
Out[2]= $Failed
The -L (libraries path) and -I (include path) options shown in the output are mentioned briefly in the gcc docs and in this answer by @Szabolcs.
$CCompiler = {"Compiler" -> CCompilerDriver\MinGWCompiler`MinGWCompiler, "CompilerInstallation" -> "C:\Program Files\mingw-builds\x64-4.8.1-posix-seh-rev5\mingw64\bin", "CompilerName" -> Automatic};` help? – xzczd Oct 09 '14 at 07:15CreateExecutable::badcomperror message, which states:Compiler specification "Compiler"->CCompilerDriver\MinGWCompiler`MinGWCompiler does not specify a compiler driver listed by CCompilers[Full].` – dionys Oct 09 '14 at 08:21CCompilers[Full]? – xzczd Oct 09 '14 at 08:25Needs["CCompilerDriver\"];Needs["CCompilerDriver`GenericCCompiler`];,CCompilers[Full]returns{{Name->Intel Compiler,Compiler->CCompilerDriver`IntelCompiler`IntelCompiler,CompilerInstallation->None,CompilerName->Automatic},{Name->Generic C Compiler,Compiler->GenericCCompiler,CompilerInstallation->None,CompilerName->Automatic}}` – dionys Oct 09 '14 at 08:44\\binisn't the issue. Just found a 64-bit machine and tested OP's settings, I only changed the"CompilerInstallation"to mine i.e."C:\\TDM-GCC-64\\bin", and it works well. BTW, why you think your test code failed to compile? What's the output of yourgreeter? – xzczd Oct 09 '14 at 10:22greeter. – dionys Oct 09 '14 at 11:51$Failedand gives the errorCreateExecutable::instl, and there aren't any spaces or strange characters in the "CompilerName" setting. What else can be quoted or escaped? – dionys Oct 10 '14 at 12:59"CompilerInstallation" -> "\"C:...bin\""? – celtschk Oct 18 '14 at 22:40CreateExecutable::instl. So I think the installation directory is being read properly either way (spaces escaped and no quotes, or everything in escaped quotes). But I'm still getting$FailedfromCreatExecutableand I get the error:Compile::nogenfromCompile. – dionys Oct 18 '14 at 23:09