Nic*_*ble 11 c compiler-construction gcc wolfram-mathematica mathematica-8
我在MacOSX上运行Mathematica 8,尝试将最简单的程序编译为C.任何与C有关的东西都不能在Mathematica中运行.我安装了GCC 4.2; 我甚至用XCode多次重新安装它.这就是我正在做的和我得到的错误:
首先,我总是评估命令
Needs["CCompilerDriver`"]
Run Code Online (Sandbox Code Playgroud)
如果我将编译目标设置为C,
c = Compile[ {{x}}, x^2 + Sin[x^2], CompilationTarget -> "C"];
Run Code Online (Sandbox Code Playgroud)
我得到一个错误,其中包含:Compile :: nogen:无法从已编译的函数创建库.
如果我尝试创建一个库,
demoFile = FileNameJoin[{$CCompilerDirectory,"SystemFiles","CSource","createDLL_demo.c"}];
lib = CreateLibrary[{demoFile},"testLibrary"]
Run Code Online (Sandbox Code Playgroud)
我收到消息$ Failed.Wolfram说这是因为我没有安装C编译器.我觉得很难相信因为我跑的时候
CCompilers[]
Run Code Online (Sandbox Code Playgroud)
它告诉我我已经安装了GCC:{{"Name" - >"GCC","Compiler" - > CCompilerDriver'GCCCompiler`GCCCompiler,"CompilerInstallation" - >"/ usr/bin","CompilerName" - >自动}}
更重要的是,终端说我也安装了GCC !! 任何帮助,将不胜感激.我真的很想将Mathematica编译成C.
Sza*_*lcs 12
在这个答案中,我将收集一些针对类似问题的调试步骤,以供将来参考.随意编辑/改进它们.
如果编译为C代码不能从Mathematica 8,
检查您是否安装了受支持的 C编译器,它是否正常工作(显而易见).
请注意,编译器不一定必须在PATH,至少在Windows/Visual Studio上它不必.
检查Mathematica是否识别编译器
<< CCompilerDriver`
CCompilers[]
Run Code Online (Sandbox Code Playgroud)
将列出Mathematica已知的编译器.
Compiler`$CCompilerOptions = {"ShellCommandFunction" -> Print};
Compile[{{x}}, x^2, CompilationTarget -> "C"];
Run Code Online (Sandbox Code Playgroud)
请注意,"ShellCommandFunction" -> Print该命令将不会被执行,因此你需要重新设置Compiler`$CCompilerOptions到{}后这一步完成后,再次允许执行命令.
Compiler`$CCompilerOptions = {"ShellOutputFunction" -> Print};
Compile[{{x}}, x^2, CompilationTarget -> "C"];
Run Code Online (Sandbox Code Playgroud)这最后两个步骤有望为您提供足够的线索继续进行.使用此信息,您可以检查是否将正确的库/包含路径传递给编译器(在gcc/icc的情况下,查看-L指定库路径的-I选项和指定包含路径的选项).然后检查这些路径中是否存在所需的包含和库文件.
| 归档时间: |
|
| 查看次数: |
3475 次 |
| 最近记录: |