3
$\begingroup$

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.

$\endgroup$
8
  • $\begingroup$ I'm getting a similar error with Compile when trying to use GCC as the GenericCCompiler ... details in this question. $\endgroup$
    – dionys
    Commented Oct 22, 2014 at 15:48
  • $\begingroup$ Have you checked writing permissions to the standard output folder for the library? Maybe mathematica is not allowed to write files there. $\endgroup$
    – Wizard
    Commented Oct 22, 2014 at 16:58
  • $\begingroup$ How do I check that? Also, I'm the admin on my computer. $\endgroup$ Commented Oct 22, 2014 at 20:53
  • $\begingroup$ When I do CreateLibrary[str, "funLib"], I get $Failed $\endgroup$ Commented Oct 22, 2014 at 21:00
  • $\begingroup$ @Wizard In this page reference.wolfram.com/language/CCompilerDriver/tutorial/… 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. $\endgroup$ Commented Oct 22, 2014 at 21:05

1 Answer 1

2
$\begingroup$

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.

$\endgroup$
4
  • $\begingroup$ That's it. Thanks ;) $\endgroup$ Commented Oct 23, 2014 at 12:16
  • $\begingroup$ Wizard, is there a way to make this change permanent? Every time I restart mathematica, it assumes the compiler to be version 11 and not 12... $\endgroup$ Commented Oct 24, 2014 at 11:43
  • 1
    $\begingroup$ @Anoldmaninthesea.: One way would be to add the definition of the $CCompiler variable to the init.m file of mathematica, which is executed before the frontend or kernel starts. Take a look at init.m in the mathematica documentation for further details and the location of the file. $\endgroup$
    – Wizard
    Commented Oct 24, 2014 at 22:14
  • $\begingroup$ Much Obliged. ;) $\endgroup$ Commented Oct 25, 2014 at 12:39

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.