15
$\begingroup$

The documentation for CompilationTarget says, "if you do not have a suitable C compiler then you will not be able to set CompilationTarget to C". Well at this time, I don't have a compiler installed on either of my computers running Windows XP, or Windows 7. Is it safe to say that any compiler that will run with my OS will be "suitable"? If it isn't that simple, can you recommend a compiler?

$\endgroup$
2
  • 2
    $\begingroup$ I believe any compiler that works on your OS is "suitable", but not all compilers will be automatically detected and configured. You will need to pay attention to the "bitness" of the compiler: a 64-bit version of Mathematica will need a compiler that can produce 64-bit executables. The 32-bit version will need one that can produce 32 bit executables. If you are on Windows, the easiest and most convenient way is to install the command line compiler from the Windows SDK. The docs only tell your about compilers that have been tested, but others should work too, if properly configured. $\endgroup$
    – Szabolcs
    Jun 17, 2012 at 8:28
  • $\begingroup$ What Szabolcs says is essentially correct and helpful with one refinement: only certain C compilers can produce a library that the Mathematica kernel can load successfully. For example, by default the Cygwin gcc produces libraries that require the Cygwin DLL, and the kernel has issues loading this DLL. To use Cygwin gcc, you need to load the MinGW Cygwin package and use the Cygwin gcc with the -mnocygwin option. This may be resolved in future versions of Mathematica, but is an example of the type of issue you may run into using some arbitrary C compiler. $\endgroup$
    – Joel Klein
    Sep 28, 2012 at 21:03

3 Answers 3

8
$\begingroup$

I believe that any compiler that works on your system is suitable, but those compilers that are not explicitly supported by the CCompilerDriver` package will need manual configuration, which might be quite a bit of work.

It is important though to use a 64-bit compiler with a 64-bit version of Mathematica and a 32-bit compiler with the 32-bit version.

(Note: I think CompilationTarget -> "C" doesn't need to link against any libraries which will simplify setting up a compiler for this use compared to using it with MathLink.)

If your OS is Windows, I recommend that you use Microsoft's command line compiler from the Windows SDK. This comes in both 32-bit and 64-bit varieties and should be auto-detected by Mathematica (saving effort).

If you choose to use the popular MinGW version of GCC on Windows, the 64-bit version will need a bit of manual configuration (i.e. it's not so convenient to set up). If you only run a 32-bit version of Mathematica, you can download this 32 version of MinGW, extract it, and place the MinGW directory at C:\MinGW (this location is important as it lets Mathematica auto-detect the compiler!).

$\endgroup$
9
$\begingroup$

CCompilers[Full] will list all compilers supported on your $SystemID:

In[1]:= Needs["CCompilerDriver`"]
CCompilers[Full]

Out[2]= {{"Name" -> "Visual Studio", 
  "Compiler" -> 
   CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, 
  "CompilerInstallation" -> None, 
  "CompilerName" -> Automatic}, {"Name" -> "MinGW", 
  "Compiler" -> CCompilerDriver`MinGWCompiler`MinGWCompiler, 
  "CompilerInstallation" -> None, 
  "CompilerName" -> Automatic}, {"Name" -> "Cygwin GCC", 
  "Compiler" -> CCompilerDriver`CygwinGCC`CygwinGCC, 
  "CompilerInstallation" -> None, 
  "CompilerName" -> Automatic}, {"Name" -> "Intel Compiler", 
  "Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler, 
  "CompilerInstallation" -> None, 
  "CompilerName" -> Automatic}, {"Name" -> "Generic C Compiler", 
  "Compiler" -> CCompilerDriver`GenericCCompiler`GenericCCompiler, 
  "CompilerInstallation" -> None, "CompilerName" -> Automatic}}

You may also be interested in this question:

How to install and configure Intel C++ Compiler for Mathematica correctly?

$\endgroup$
5
$\begingroup$

I believe this is answered in Specific Compilers:

GCC

The CCompilerDriver package has been tested with several versions of the GNU Compiler Collection (http://gcc.gnu.org) on a variety of different platforms.

$SystemID   Tested versions of GCC
Linux           4.0
Linux-x86-64    4.0
MacOSX          4.0
MacOSX-x86      4.0
MacOSX-x86-64   4.0

Tested versions of GCC and platform.

etc...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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