3

I have windows 8, Mathematica 9, and I've just installed Microsoft Visual Studio 2013 with update 3.

I'm try to run Compile with the option CompilationTarget->"C".

Needs["CCompilerDriver`"];

In[60]:= CCompilers[]

Out[60]= {{"Name" -> "Visual Studio", 
  "Compiler" -> 
   CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, 
  "CompilerInstallation" -> 
   "C:\\Program Files (x86)\\Microsoft Visual Studio 11.0", 
  "CompilerName" -> Automatic}}

But when trying to run an example of Mathematica Help I get:

In[61]:= cGen = 
 Compile[{{x}}, x^2 + Sin[x^2], CompilationTarget -> "C"]

During evaluation of In[61]:= Compile::nogen: A library could not be generated from the compiled function. >>

The Mathematica help doesn't have information on how to solve this. This error appears always when I try to use Compile with CompilationTarget option...

Any help would be appreciated.

An old man in the sea.
  • 2,527
  • 1
  • 18
  • 26
  • I'm getting a similar error with Compile when trying to use GCC as the GenericCCompiler ... details in this question. – dionys Oct 22 '14 at 15:48
  • Have you checked writing permissions to the standard output folder for the library? Maybe mathematica is not allowed to write files there. – Wizard Oct 22 '14 at 16:58
  • How do I check that? Also, I'm the admin on my computer. – An old man in the sea. Oct 22 '14 at 20:53
  • When I do CreateLibrary[str, "funLib"], I get $Failed – An old man in the sea. Oct 22 '14 at 21:00
  • @Wizard In this page http://reference.wolfram.com/language/CCompilerDriver/tutorial/CreatingLibrary.html

    It says if the create library command fails I do not have a suitable compiler... How can it be, if I downloaded Microsoft Visual Studio 2013 with update 3 (MVS)? Unless I had to set up mathematica compiler in specific way. I just installed the MVS, and Mathematica seemed to detect it.

    – An old man in the sea. Oct 22 '14 at 21:05
  • @Anoldmaninthesea: You should try loading Needs["CCompilerDriver"]and then runCCompilers[]to get the information about your CCompiler setup. Your MVS Compiler should show up there. If it does not you might be able to fix the problem by manually setting the$CCompilervariable like$CCompiler = {"Name"->"Visual Studio", "Compiler"->CCompilerDriverVisualStudioCompilerVisualStudioCompiler, "CompilerInstallation"->"C:\Program Files (x86)\Microsoft Visual Studio 10.0", "CompilerName"->Automatic}` – Wizard Oct 23 '14 at 10:53
  • @Wizard I've already done that as is on the question... – An old man in the sea. Oct 23 '14 at 10:56
  • @Anoldmaninthesea: Sorry, did not recall correctly and did not take an additional look at the question. But here is a question: Why does mathematica show Microsoft Visual Studio 11.0? You have version 2013 installed, that would be Microsoft Visual Studio 12.0. So the setup is definitely not right. Try setting it manually via $CCompiler variable. – Wizard Oct 23 '14 at 11:19

1 Answers1

2

Check that your Compiler setup is actually right. To see what your CCompiler setup is right now you should load the package CCompilerDriver via Needs["CCompilerDriver"] and execute CCompilers[], which you already did. In your case mathematica shows, that the compiler is set to MVS 2012 (this is version 11.0) not version 2013 (which would be version 12.0). To fix this, manually set the CCompiler via setting the variable $CCompiler:

$CCompiler = {"Name" -> "Visual Studio", "Compiler" -> CCompilerDriver`VisualStudioCompiler`VisualStudioCompiler, "CompilerInstallation" -> "C:\\Program Files (x86)\\Microsoft Visual Studio 12.0", "CompilerName" -> Automatic}

Take care of setting the "CompilerInstallation" string to the right value. In the example above I chose the standard folder for Visual Studio 2013.

Wizard
  • 2,720
  • 17
  • 28