如何在Win7(x64)上使用英特尔C++编译器(x86)将Mathematica编译为C代码
How to compile Mathematica to C code with intel C++ compiler (x86) on Win7(x64)?
我的操作系统是windows 7 64位。我安装了Microsoft C++2008速成版和"英特尔C++编译器"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 -> "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:\...AppDataRoamingMathematicaApplicationDataCCompilerDriverBuildFoldervax-5844compiledFunction5.dll. >>
During evaluation of In[3]:= Compile::nogen: A library could not be generated from the compiled function. >>
我想我需要指定一个默认的"TargetSystemID"-> "Windows"
,因为我的平台是x64,但不知道如何在Mathematica中设置这样的选项。
我遗漏了什么吗?
PS:我最近不想安装Microsoft Visual Studio。
在第一个代码块中,您指定了所需的编译器。在第二个例子中,你没有——所以可能是Mathematica不"知道"你安装的编译器。
运行Needs["CCompilerDriver`"]
,然后运行CCompilers[Full]
,查看Mathematica了解哪些编译器。也可以看看全局$CCompilerDirectory
。
如果您的英特尔和/或Microsoft编译器未显示,请按照《CCompilerDriver用户指南》中的"特定编译器"页进行操作。为了让你的英特尔编译器工作,我认为也许以下就足够了:
$CCompiler = {
"Compiler" -> CCompilerDriver`IntelCompiler`IntelCompiler,
"CompilerInstallation"->"C:\Program Files (x86)\Intel\Compiler\11.1\072\"}
也就是说,如果我使用上面的代码将编译器的目录更改为错误,那么我得到的第一个错误类型(在Compile::nogen
之前)是CreateLibrary::instl
,而不是您得到的LibraryFunction::libload
消息。也许您的默认生成目录$CCompilerDefaultDirectory
有问题。。。
针对您的PS,英特尔C++v11.1 Windows版编译器已在他们测试过的编译器列表中,因此您不需要安装MS Visual Studio。另一方面,您可以通过MiniGW或CygWin尝试GCC for Windows(另请参阅SO/187990)。
- 为x86而非x64编译时出错
- C++如何仅使用MOV在x86上实现发布和获取
- 在 c++ 中使用 x86 DIV 的这个 asm 块有什么用?
- 在 x86 上实现 std::atomic_thread_fence(std::memory_order_seq_cst
- 如何将C++子例程链接到 x86 程序集程序?
- 如何在 x86 处理器上实现"锁定添加"
- 您选择的 CPU 不支持 x86-64 指令集
- std::x86 上需要memory_order_acquire围栏吗?
- 尝试使用 x86 asm SSSE3 将大端转换为小端序
- 如何在 MSVC C++中迁移 x64 的 x86 代码
- 将内联程序集尾调用函数尾声替换为用于x86/x64 msvc的Intrinsics
- 将程序从x86转换为x64
- 如果由不同的线程写入 8 字节,那么现代英特尔 x86 上的 8 字节读取是否保证理智?
- 将vector<vector<double>>从x86平台中创建的一个进程发送到x64中构建的另一个进程的最快方法是什么
- x86 32位对Cuda的支持
- 这个x86汇编代码是如何接收和存储子程序返回的数据的
- Clang:x86 FPU调用约定
- 现代C++中STL API的差异(当我在VS2017中将目标从x64切换到x86时)
- 在 Mathematica 中绘制来自 c++ 的 2D 晶格数据
- 如何在Win7(x64)上使用英特尔C++编译器(x86)将Mathematica编译为C代码