Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Mathematica does not recognize any C compiler on my computer. I run Mathematica 8.0.4.0 on Windows 7. I've tried to make sure various C compilers are installed on my computer, but I'm not sure how to get Mathematica to recognize the installation.

If the compiler is installed correctly, should Mathematica automatically recognize it, or do I have to point Mathematica to a very specific folder to find it?

I edited this post according to some of the comments below by @Szabolcs and @. I've been through http://stackoverflow.com/a/6549505/695132 , and step 2 appears to fail.

I've already been to http://forums.wolfram.com/mathgroup/archive/2011/Nov/msg00024.html, and I installed Microsoft Windows SDK v7.1 for Windows 7 and .NET Framework 4 for xI64. http://www.microsoft.com/en-us/download/details.aspx?id=8442

I also got the Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1: http://www.microsoft.com/download/en/details.aspx?id=4422

Please forgive me for not knowing how to check to see if the compiler is working. I simply don't even know where to start with Visual Studios and all that.

Needs["CCompilerDriver`"]
DefaultCCompiler[]
CCompilers[Full]
CCompilers[]

gives the following output:

$Failed
{}
{{"Name" -> "Intel Compiler", 
  "Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler, 
  "CompilerInstallation" -> None, 
  "CompilerName" -> Automatic}, {"Name" -> "Generic C Compiler", 
  "Compiler" -> CCompilerDriver`GenericCCompiler`GenericCCompiler, 
  "CompilerInstallation" -> None, "CompilerName" -> Automatic}}

I get the following error when I try to compile:

CreateLibrary::instl: The compiler installation directive "CompilerInstallation" -> C:\Program Files (x86)\Microsoft Visual Studio 10.0\SDK does not indicate a usable installation of Visual Studio. >>

My question is similar to this question thread, but I don't have enough reputation to ask on that thread. http://stackoverflow.com/questions/6537457/gcc-installed-mathematica-still-wont-compile-to-c

I also have "gcc" show up in a search in various folders under Python27 and MinGW, but Mathematica doesn't seem to know about it. I don't care which compiler I use; I just want an easy installation.

I spent a day trying all sorts of stuff mentioned on various forums, but nothing is working. Why does Mathematica not come out of the box with a working compiler?

share|improve this question
1  
You should not change $CCompilers or set anything else special. Please restart Mathematica, and evaluate Needs["CCompilerDriver`"]; CCompilers[] (in a fresh kernel) and post what it returns. Also try ` Compile[x, x, CompilationTarget -> "C"]. Actually iy would be best if you went through those 4 steps I posted [here](http://stackoverflow.com/a/6549505/695132) and posted the results. Again: don't change things like $CCompiler` before testing!! Can you start a Windows SDK Command Prompt and test manually that the compiler works (cl.exe)? –  Szabolcs May 13 '12 at 6:38
    
If you have a 64-bit system, you have two free choices: 1. The 64 bit command line compiler from the Windows 7 SDK. This should 'just work' after installation. (It is not necessary to install Visual Studio, just the compiler from the SDK!!) 2. a 64-bit MinGW: this will require manual setup using the generic compiler driver (there are step by step instructions specifically for this toolchain in the docs), and is a lot more trouble to get working. –  Szabolcs May 13 '12 at 6:40
1  
@Szabolcs although MinGW-w64 gcc can be made to work (I use it, for example) the instructions in the docs aren't sufficient; proper support needs extra work that isn't documented anywhere officially. If the goal here is easy installation, Visual C++ 2010 is definitely the best option. I posted some step-by-step instructions here. (I won't claim this is the only way, but to me it seemed like the easiest route.) –  Oleksandr R. May 13 '12 at 6:50
    
@Oleksandr I agree, that's why I said it's a lot of trouble. I used MinGW-w64 for a while as well, but I don't remember if the sintructions in the docs were sufficient or not. I remember I set it up based on those though. –  Szabolcs May 13 '12 at 6:59
1  
This question might be retitled to indicate it is specific to Windows 64-bit, if that is the intent. Compiler setup is typically much simpler on Linux, MacOS, and even on 32-bit Windows where Cygwin and MinGW pretty much just work. –  Joel Klein May 15 '12 at 19:02
show 12 more comments

1 Answer

up vote 11 down vote accepted

First, be sure to read the Specific Compilers section of the CCompilerDriver User Guide. This is the official place where the nuts and bolts of using external C compilers is discussed.

In that section, "Visual Studio Express and 64-Bit Targets" is where compilation on 64-bit Windows is discussed.

Some things to check when setting up:

  • Be sure to install .NET Framework 4 before Windows SDK 7.1. Without this, the Windows SDK installer may (if you don't have it) give a warning about this, and the Visual C++ component will be grayed out.

  • In the install wizard for the Windows SDK, be sure any components that say "Visual C++" are selected for installation.

If you're not sure if you have the .NET Framework 4, you can try running the Windows SDK 7.1 installer and look carefully for a warning dialog. If you don't get a dialog warning that .NET Framework is not detected, and the Visual C++ component is selectable for installation, then you may proceed with installing just the Windows SDK.

I can confirm that you don't need to install Visual Studio Express first, you can get away with installing only the .NET Framework 4 (if needed) and then the Windows SDK.

Edited to add: In answer to "If the compiler is installed correctly, should Mathematica automatically recognize it, or do I have to point Mathematica to a very specific folder to find it?", for Visual Studio it is automatically recognized through an environment variable or the registry. Of the compilers that are directly supported, as opposed to a "Generic" C compiler, they are all automatically detected in some form, depending on the specifics of the compiler.

share|improve this answer
    
This did it! Without uninstalling Windows SDK (again), I simply installed the .NET Framework 4 link, restarted my computer, and then now it works. CCompilers[] now gives {{"Name" -> "Visual Studio", "Compiler" -> CCompilerDriverVisualStudioCompiler`VisualStudioCompiler, "CompilerInstallation" -> "c:\\Program Files (x86)\\Microsoft Visual Studio 10.0", "CompilerName" -> Automatic}}` Apparently, this link didn't install .Net Framework 4. –  Paul May 15 '12 at 21:15
    
Yes, it's confusing that something called "Windows SDK for Windows 7 and the .NET Framework 4" does not install .NET Framework 4. –  Joel Klein May 16 '12 at 13:54
    
Yes. I reinstalled the .Net Framework, it also works without reboot. So the .Net Framework installer in Intel C Compiler has some problems. After install the ICC, you must reinstall the .Net Framework in order to help Mathematica recognize the compiler. –  DaoTRINH Feb 5 at 16:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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