发生编译错误怎样处理?
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 15
虽然
1 Compile本身就有HoldAll属性所以不用另加。
2 RuntimeOptions -> {"Speed"}明显放错位子了你是不是贴过来之后又手动改过。
但上面这两点都不是引发编译失败的原因。就我所知,可能引发上面的编译问题的原因有:
1 没装C编译器。吧里有相关帖,就是精品区算勾股数的那帖。
2 装了C编译器但是没配置好。这条又至少可以分为GCC系编译器的配置问题和Visual Studio版本过新导致的不兼容问题两类,印象里吧里也都有相关帖,就是不知道好不好找。
3 Mathematica换版本时旧信息没清干净导致新版的注册不彻底。(至少有一个人在版本9遇到过这个问题——那个人就是我。)
你是哪类?
2016年04月02日 15点04分 2
1是为了去除Protected,2是改过,Visual Studio我用的是2015,咋配置?
2016年04月02日 16点04分
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
level 11
感谢楼主分享解决方法[真棒]
2016年10月17日 08点10分 4
1