# C compiler options passed by Mathematica

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["CCompilerDriverGenericCCompiler"]
$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*)


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. • Does $CCompiler = {"Compiler" -> CCompilerDriverMinGWCompilerMinGWCompiler, "CompilerInstallation" -> "C:\\Program Files\\mingw-builds\\x64-4.8.1-posix-seh-rev5\\mingw64\\bin", "CompilerName" -> Automatic}; help? – xzczd Oct 9 '14 at 7:15
• @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"->CCompilerDriverMinGWCompilerMinGWCompiler does not specify a compiler driver listed by CCompilers[Full]. – dionys Oct 9 '14 at 8:21
• I have TDM-GCC installed in my computer. What's the output if you run CCompilers[Full]? – xzczd Oct 9 '14 at 8:25
• @xzczd With a fresh kernel after calling Needs["CCompilerDriver"];Needs["CCompilerDriverGenericCCompiler];, CCompilers[Full] returns {{Name->Intel Compiler,Compiler->CCompilerDriverIntelCompilerIntelCompiler,CompilerInstallation->None,CompilerName->Automatic},{Name->Generic C Compiler,Compiler->GenericCCompiler,CompilerInstallation->None,CompilerName->Automatic}}` – dionys Oct 9 '14 at 8:44