How do I get Mathematica to recognize a C compiler on a 64-bit Windows machine?



Mathematica does not recognize any C compiler on my computer. I run Mathematica 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 , and step 2 appears to fail.

I've already been to, and I installed Microsoft Windows SDK v7.1 for Windows 7 and .NET Framework 4 for xI64.

I also got the Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1:

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.


gives the following output:

{{"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.

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?


Posted 2012-05-13T03:37:16.340

Reputation: 705


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 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 – 2012-05-13T06:38:57.980

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 – 2012-05-13T06:40:52.627


@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. – 2012-05-13T06:50:10.670

@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 – 2012-05-13T06:59:44.647

@Szabolcs yes, it works superficially if you follow those instructions but you will get link errors if you try to use it seriously. Making it work properly requires GNU COFF format import libraries; since the generic C compiler support doesn't attempt to link against libraries at all, I found the best approach to be modifying MinGWCompiler.m so that it supports both 32- and 64-bit MinGW. – Oleksandr R. – 2012-05-13T07:11:10.177

@Oleksandr That's good to be aware of. Can you give an example of when there will be problems (so I can avoid them)? – Szabolcs – 2012-05-13T09:27:58.817

@Szabolcs I think in practice you'd probably know when you were going to encounter problems--essentially whenever you need to link a library such as the MathLink libraries or the Wolfram RTL. By way of a concrete example, I showed here that the MathLink demo from LibraryLink won't link properly without the needed import libraries being set up.

– Oleksandr R. – 2012-05-14T00:54:21.533

Paul, I'm no expert on Visual C++ (as I said, I don't use it myself), but when I tried it previously, per the steps I mentioned on MathGroup, it worked first time. Did you follow the instructions I gave there exactly, and without having anything else related (e.g. Visual Studio Express) installed beforehand? Can you check to see if you have the file %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\bin\vcvarsamd64.bat? (Mathematica looks for this and it should be there if you followed the steps I described.) If not, where (if anywhere) is it? – Oleksandr R. – 2012-05-14T01:06:14.043

@Paul, it seems that for some reason Mathematica is not finding your Visual Studio installation. It's difficult to figure out why without having access to your machine, but let's try. I looked at the compiler driver source, and it seems to be looking for the compiler installation path in certain environment variables. Can you check if you have the environment variable VS100COMNTOOLS set? In Mathematica, evaluate Environment["VS100COMNTOOLS"] and tell us what it returns. You can also get the list of all environment variables by typing set into a Windows command prompt (cmd.exe). – Szabolcs – 2012-05-14T12:42:43.040

Running Environment["VS100COMNTOOLS"] gives $Failed.

@OleksandrR., vcvarsamd64.bat does not exist. I installed the x64 version of the SDK from Should I have installed a different one? I also probably installed more than just the headers and libraries just to be safe. Is that bad? Do I need to uninstall everything and start over?

– Paul – 2012-05-14T20:41:02.043

@Paul the x64 version is correct. I don't know if installing other things will affect the result as I didn't try it (since I knew that only the headers and libraries are needed). While it's almost certainly possible to fix your installation without uninstalling everything and starting from scratch, the exact steps needed are going to be next to impossible to determine without having access to your system, so yes, I suggest just starting again from the beginning. Do make sure you install into %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\SDK this time too. – Oleksandr R. – 2012-05-14T20:52:37.753

Just to be clear, I have vcvars32.bat in that directory. Does that offer any help as to what part of the installation I did wrong? I did save to %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\SDK on my install. – Paul – 2012-05-14T20:54:42.040

@Paul sorry, I wrote the path incorrectly. vcvarsamd64.bat should be in the %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\VC\bin\amd64 directory if it's present. Can you find it there? – Oleksandr R. – 2012-05-14T21:00:20.280

No, and it's nowhere in all of Program Files. I'm curious why I need a file with "amd" in it, when I have an Intel processor. – Paul – 2012-05-14T21:09:55.417

let us continue this discussion in chat

– Paul – 2012-05-14T22:00:14.797

Can I have you check a couple things? $SystemID -- is it "Windows" or "Windows-x86-64"? What does this return: Developer`EnumerateRegistrySubkeys["HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows"] – Joel Klein – 2012-05-14T22:05:44.297

1This 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 – 2012-05-15T19:02:20.317

I followed exactly the same way as Joel Klein suggested (first install .NET Framework 4 then install Windows SDK and restart system), but still got the same problem in Paul's post. My system: Win7 64 bit + Mathematica 11.2 + Microsoft Visual Studio 2008. Could you help me about this problem? @Szabolcs – Wilhelm – 2018-02-23T04:38:00.637

I installed the Microsoft Visual C++ 2010 Express, although I already have Microsoft Visual Studio 2008. This fixed my issue. – Wilhelm – 2018-02-23T07:03:00.687



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.

Joel Klein

Posted 2012-05-13T03:37:16.340

Reputation: 4 935

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. – Nam Nguyen – 2014-02-05T16:01:47.760

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" -> CCompilerDriverVisualStudioCompilerVisualStudioCompiler, "CompilerInstallation" -> "c:\\Program Files (x86)\\Microsoft Visual Studio 10.0", "CompilerName" -> Automatic}}

Apparently, this link didn't install .Net Framework 4.

– Paul – 2012-05-15T21:15:52.057

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 – 2012-05-16T13:54:57.750

I followed exactly the same way as you suggested (first install .NET Framework 4 then install Windows SDK), but still got the same problem in Paul's post. My system: Win7 64 bit + Mathematica 11.2. Could you help me about this problem? – Wilhelm – 2018-02-23T04:22:38.153

I installed the Microsoft Visual C++ 2010 Express, although I already have Microsoft Visual Studio 2008. This fixed my issue. – Wilhelm – 2018-02-23T07:03:04.557

1Appears that this does not work for 11.3. Under 11.2 Mathematica properly detects the installed compilers, but 11.3 fails to do so. – Markus Roellig – 2018-04-12T12:39:50.450