4
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Does $CCompiler = {"Compiler" -> CCompilerDriver`MinGWCompiler`MinGWCompiler, "CompilerInstallation" -> "C:\\Program Files\\mingw-builds\\x64-4.8.1-posix-seh-rev5\\mingw64\\bin", "CompilerName" -> Automatic}; help? $\endgroup$ – xzczd Oct 9 '14 at 7:15
  • $\begingroup$ @xzczd Do you have MinGWCompiler defined on your system? When I try with that setting I get the CreateExecutable::badcomp error message, which states: Compiler specification "Compiler"->CCompilerDriver`MinGWCompiler`MinGWCompiler does not specify a compiler driver listed by CCompilers[Full]. $\endgroup$ – dionys Oct 9 '14 at 8:21
  • $\begingroup$ I have TDM-GCC installed in my computer. What's the output if you run CCompilers[Full]? $\endgroup$ – xzczd Oct 9 '14 at 8:25
  • 1
    $\begingroup$ @xzczd With a fresh kernel after calling Needs["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}} $\endgroup$ – dionys Oct 9 '14 at 8:44
  • 1
    $\begingroup$ "C:\Program is not recognized……" seems that the white space in the path isn't recognized correctly. I'm not sure about the reason. Did you forget to add double quotation marks somewhere? $\endgroup$ – xzczd Oct 10 '14 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.