【问题标题】:How to compile Mathematica to C code with intel C++ compiler (x86) on Win7(x64)?如何在 Win7(x64) 上使用 intel C++ 编译器 (x86) 将 Mathematica 编译为 C 代码?
【发布时间】:2012-01-21 23:39:27
【问题描述】:

我的操作系统是 Windows 7 64 位。我安装了 Microsoft C++ 2008 Express 版和 Intel C++ Compiler v11.1 x86 版。

现在我可以在 Mathematica 中成功编译 x86 C 代码,例如

    In[1]:= Needs["CCompilerDriver`"]
    In[2]:= greeter = CreateExecutable[StringJoin["#include <stdio.h>\n", "int main(){\n", "  printf(\"Hello world.\\n\");\n", "}\n"], "hiworld", 
     "Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler, 
     "CompilerInstallation" -> "C:\\Program Files (x86)\\Intel\\Compiler\\11.1\\072\\", 
     "CompilerName" -> Automatic, "TargetSystemID" -> "Windows"]

    Out[2]= "C:\\...\\AppData\\Roaming\\Mathematica\\\
       SystemFiles\\LibraryResources\\Windows-x86-64\\hiworld.exe"

但是无法使用CompilationTarget -&gt; "C"编译这样的函数

    In[3]:= f = Compile[{x, y}, Sqrt[x^2 + y^2], CompilationTarget -> "C"]

    During evaluation of In[3]:= LibraryFunction::libload: The function compiledFunction5 was not loaded from the file C:\\...\AppData\Roaming\Mathematica\ApplicationData\CCompilerDriver\BuildFolder\vax-5844\compiledFunction5.dll. >>
    During evaluation of In[3]:= Compile::nogen: A library could not be generated from the compiled function. >>

我想我需要指定一个默认的"TargetSystemID"-&gt; "Windows",因为我的平台是 x64,但不知道如何在 Mathematica 中设置这样的选项。

我在这里漏掉了什么吗?

PS:我最近不想安装 Microsoft Visual Studio。

【问题讨论】:

    标签: c++ compiler-construction wolfram-mathematica 64-bit mathematica-8


    【解决方案1】:

    在您的first code block 中,您指定了所需的编译器。在第二个你没有 - 所以它可能是 Mathematica 不“知道”你已经安装的编译器。

    运行 Needs["CCompilerDriver`"] 然后运行 ​​CCompilers[Full] 以查看 Mathematica 知道哪些编译器。也可以看看全球$CCompilerDirectory

    如果您的 Intel 和/或 Microsoft 编译器未显示,请关注 CCompilerDriver User GuideSpecific Compilers 页面。 为了让您的英特尔编译器正常工作,我认为以下内容可能就足够了:

    $CCompiler = {
     "Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler,
     "CompilerInstallation"->"C:\\Program Files (x86)\\Intel\\Compiler\\11.1\\072\\"}
    

    也就是说 - 如果我使用上面的代码将目录更改为我的编译器错误,那么我得到的第一个错误类型(Compile::nogen 之前)是CreateLibrary::instl,而不是你的 LibraryFunction::libload 消息有。您的默认构建目录可能有问题:$CCompilerDefaultDirectory...

    针对您的 PS,适用于 Windows 的英特尔 C++ v11.1 编译器在他们测试过的编译器列表中,因此您不需要安装 MS Visual Studio。另一方面,您可以通过 MiniGW 或 CygWin 为 Windows 尝试GCC(另请参阅SO/187990)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2011-12-03
      • 2011-08-23
      • 1970-01-01
      相关资源
      最近更新 更多