【发布时间】:2011-06-30 15:45:27
【问题描述】:
我在 MacOSX 上运行 Mathematica 8,试图将最简单的程序编译为 C。任何与 C 相关的东西在 Mathematica 中都不起作用。我安装了 GCC 4.2;我什至用 XCode 多次重新安装它。这是我正在做的事情以及我遇到的错误:
首先,我总是评估命令
Needs["CCompilerDriver`"]
如果我将编译目标设置为 C,
c = Compile[ {{x}}, x^2 + Sin[x^2], CompilationTarget -> "C"];
我收到一条错误消息:Compile::nogen : A library could not be created from the compiled function.
如果我尝试创建一个库,
demoFile = FileNameJoin[{$CCompilerDirectory,"SystemFiles","CSource","createDLL_demo.c"}];
lib = CreateLibrary[{demoFile},"testLibrary"]
我收到一条消息 $Failed。 Wolfram 说这是因为我没有安装 C 编译器。我觉得这很难相信,因为当我跑步时
CCompilers[]
它告诉我已经安装了 GCC:{{"Name" -> "GCC", “编译器”-> CCompilerDriver'GCCCompiler`GCCCompiler, "CompilerInstallation" -> "/usr/bin", "CompilerName" -> 自动}}
更重要的是,终端说我也安装了 GCC!任何帮助,将不胜感激。我真的很想将 Mathematica 编译为 C。
【问题讨论】:
-
文档说 MMA 已经用 GCC 4.0 进行了测试。但是,我不希望微小的版本差异成为您问题的根源。你检查demo文件是否存在?
-
是的,演示文件存在于这个位置:/Applications/Mathematica.app/AddOns/Applications/CCompilerDriver/\SystemFiles/CSource/createDLL_demo.c
-
@sjoerd 这不是 gcc 版本,例如在我的,
Import["!gcc --version", "Text"]说i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)(后面是版权通知) -
什么版本的 Mathematica,什么版本的 OS X?它适用于 V8.0.1 和 OS X 10.6.8。 (我的 GCC 版本与 acl 的版本相同。)我假设您可以成功编译一个简单的“hello world”程序?
-
我刚刚在终端中使用 gcc 编译并运行了一个“hello world”程序。它工作得很好。我正在运行 OSX 10.6.7 和 V8.0.0。
标签: c gcc compiler-construction wolfram-mathematica mathematica-8