发生编译错误怎样处理?
mathematica吧
全部回复
仅看楼主
level 13
◆Kyubey 楼主
代码:
Attributes[Compile] = {HoldAll}
SetOptions[Compile,
CompilationOptions -> {"InlineExternalDefinitions" -> True},
CompilationTarget -> "C", Parallelization -> True,
RuntimeAttributes -> {}, RuntimeOptions -> "Quality"]
(*编译选项*)
arg = Compile[{x, _Complex},
If[Abs[x] != \[Pi],
\[Pi] FractionalPart[x/\[Pi]],
RuntimeOptions -> {"Speed"}, x]]
输出:
Out[205]= {HoldAll}
Out[206]= {CompilationOptions->{InlineExternalDefinitions->True},CompilationTarget->C,Parallelization->True,RuntimeAttributes->{},RuntimeOptions->{Speed}}
\:6B63\:5728\:8BA1\:7B97In[205]:= CCompilerDriver`CreateLibrary::cmperr: Compile error: LINK : fatal error LNK1104: ÎÞ\[CenterDot]¨\.b4ò¿ªÎļþ¡\[Degree]LIBCMT.lib¡\[PlusMinus] >>
\:6B63\:5728\:8BA1\:7B97In[205]:= Compile::nogen: 一个库函数不能从被编译函数中生成. >>
Out[207]= CompiledFunction[Argument count: 2
Argument types: {_Real,_Real}
]
[泪]咋样处理?
2016年04月02日 15点04分 1
level 13
◆Kyubey 楼主
已经解决,提供一个备忘。
源材料:====================================================
Here's how to get Mathematica 10.2 to recognize Visual Studio 2015's (Community Edition) C compiler (Windows 8.1).
In the Mathematica installation folders, go to SystemFiles / Components / CCompilerDriver
Make a backup copy of VisualStudioCompiler.m (disaster recovery)
Open VisualStudioCompiler.m
Scroll to $VisualStudioVersions and add "2015" to the list
Scroll to installPath["2013"] and after it, include this new line
installPath["2015"] := installPathFromEnvironment["VS140COMNTOOLS"]
These hiccups bit me:
Although I could edit VisualStudioCompiler.m, it wouldn't save to the above folder
Instead, save it elsewhere and then copy it into the above folder
It's not enough to simply install VS2015 -- once installed, within it you must yet install the C++ compiler
Once the C++ compiler is installed, open Mathematica and run:
Needs@"CCompilerDriver`"CCompilers@Full
You should see Visual Studio in the output list -- you're good to go
备忘:====================================================
1.定位Mathematica安装目录
2.搜索VisualStudioCompiler.m
3.备份
4.寻找
$VisualStudioVersions = {
行,修改为
$VisualStudioVersions = {"2015", "2013", "2012", "2010", "2008", "2005"}
5.确保存在以下行,若无加入
installPath["2005"] := installPathFromEnvironment["VS80COMNTOOLS"]
installPath["2008"] := installPathFromEnvironment["VS90COMNTOOLS"]
installPath["2010"] := installPathFromEnvironment["VS100COMNTOOLS"]
installPath["2012"] := installPathFromEnvironment["VS110COMNTOOLS"]
installPath["2013"] := installPathFromEnvironment["VS120COMNTOOLS"]
installPath["2015"] := installPathFromEnvironment["VS140COMNTOOLS"]
6.保存
7.编译前运行
Needs["CCompilerDriver`"]
CCompilers[Full]
对于Visual Studio版本太新不能识别的问题,用此法一般可解决。
2016年04月03日 11点04分 3
1