在 Win10 上为 MATLAB 编译垃圾邮件工具箱时出现错误"undeclared '_finite'"



我正在尝试使用 SPAMS v2.6(从 http://spams-devel.gforge.inria.fr/downloads.html 下载)、MATLAB R2018a 和 Win10 导入 MATLAB 中稀疏表示的 SPAMS 工具箱。我已经用MinGW64编译了MEX文件。

当我运行compile.m时发生错误,似乎某些函数/模块(我不确定如何称呼它们)可以编译,而其他函数/模块则不能。我试图评论这些功能导致错误(约占总功能的一半),其余功能运行良好,但它们无法通过 SPAMS 中的测试。我想这些功能在某种程度上是交互式的。

>> compile
Warning: Directory already exists. 
> In compile (line 150) 
compilation of: -I./linalg/ -I./prox/ prox/mex/mexSvmMisoOneVsRest.cpp
Building with 'MinGW64 Compiler (C++)'.
MEX completed successfully.
compilation of: -I./linalg/ -I./decomp/ decomp/mex/mexProjSplx.cpp
Building with 'MinGW64 Compiler (C++)'.
MEX completed successfully.
compilation of: -I./linalg/ -I./decomp/ -I./prox/ -I./dictLearn/ dictLearn/mex/mexArchetypalAnalysis.cpp
Building with 'MinGW64 Compiler (C++)'.
MEX completed successfully.
compilation of: -I./linalg/ -I./decomp/ -I./prox/ -I./dictLearn/ dictLearn/mex/mexTrainDL.cpp
Building with 'MinGW64 Compiler (C++)'.
MEX completed successfully.
compilation of: -I./linalg/ -I./decomp/ -I./prox/ -I./dictLearn/ dictLearn/mex/mexStructTrainDL.cpp
Building with 'MinGW64 Compiler (C++)'.
Error using mex
In file included from .prox/fista.h:24:0,
                 from .dictLearn/dicts.h:36,
                 from E:xmdataSPAMSspams-matlab-v2.6-2017-02-27spams-matlab-v2.6dictLearnmexmexStructTrainDL.cpp:37:
.prox/project.h: In instantiation of 'void GraphPath<T, Int>::init_graph(const GraphPathStruct<T>&) [with T = double; Int = long long int]':
.prox/fista.h:2195:17:   required from 'FISTA::GraphPathL0<T>::GraphPathL0(const FISTA::ParamReg<T>&) [with T = double]'
.prox/fista.h:3399:39:   required from 'FISTA::Regularizer<T>* FISTA::setRegularizerVectors(const FISTA::ParamFISTA<T>&, const GraphStruct<T>*, const
TreeStruct<T>*, const GraphPathStruct<T>*) [with T = double]'
.dictLearn/dicts.h:934:51:   required from 'void Trainer<T>::train_fista(const Data<T>&, const ParamDictLearn<T>&, const GraphStruct<T>*, const
TreeStruct<T>*) [with T = double]'
E:xmdataSPAMSspams-matlab-v2.6-2017-02-27spams-matlab-v2.6dictLearnmexmexStructTrainDL.cpp:268:7:   required from 'void callFunction(mxArray**,
const mxArray**, int, int) [with T = double; mxArray = mxArray_tag]'
E:xmdataSPAMSspams-matlab-v2.6-2017-02-27spams-matlab-v2.6dictLearnmexmexStructTrainDL.cpp:311:50:   required from here
.prox/project.h:3157:25: error: '_finite' was not declared in this scope
       num_arcs[i]= isinf(graph.start_weights[i]) ? 2 :  3;
.prox/project.h:3160:28: error: '_finite' was not declared in this scope
       num_arcs[i+_n]= isinf(graph.stop_weights[i]) ? 2 :  3;
.prox/project.h:3191:17: error: '_finite' was not declared in this scope
       if (!isinf(graph.start_weights[i])) {
.prox/project.h:3199:17: error: '_finite' was not declared in this scope
       if (!isinf(graph.stop_weights[i])) {
.prox/project.h: In instantiation of 'void GraphPath<T, Int>::init_graph(const GraphPathStruct<T>&) [with T = float; Int = long long int]':
.prox/fista.h:2195:17:   required from 'FISTA::GraphPathL0<T>::GraphPathL0(const FISTA::ParamReg<T>&) [with T = float]'
.prox/fista.h:3399:39:   required from 'FISTA::Regularizer<T>* FISTA::setRegularizerVectors(const FISTA::ParamFISTA<T>&, const GraphStruct<T>*, const
TreeStruct<T>*, const GraphPathStruct<T>*) [with T = float]'
.dictLearn/dicts.h:934:51:   required from 'void Trainer<T>::train_fista(const Data<T>&, const ParamDictLearn<T>&, const GraphStruct<T>*, const
TreeStruct<T>*) [with T = float]'
E:xmdataSPAMSspams-matlab-v2.6-2017-02-27spams-matlab-v2.6dictLearnmexmexStructTrainDL.cpp:268:7:   required from 'void callFunction(mxArray**,
const mxArray**, int, int) [with T = float; mxArray = mxArray_tag]'
E:xmdataSPAMSspams-matlab-v2.6-2017-02-27spams-matlab-v2.6dictLearnmexmexStructTrainDL.cpp:313:49:   required from here
.prox/project.h:3157:25: error: '_finite' was not declared in this scope
       num_arcs[i]= isinf(graph.start_weights[i]) ? 2 :  3;
.prox/project.h:3160:28: error: '_finite' was not declared in this scope
       num_arcs[i+_n]= isinf(graph.stop_weights[i]) ? 2 :  3;
.prox/project.h:3191:17: error: '_finite' was not declared in this scope
       if (!isinf(graph.start_weights[i])) {
.prox/project.h:3199:17: error: '_finite' was not declared in this scope
       if (!isinf(graph.stop_weights[i])) {

Error in compile (line 447)
    mex(args{:});

在 SPAM 附带的文件linalg/misc.h中,靠近文件顶部,有以下代码:

#if defined(_MSC_VER) || defined(_WIN32) || defined(WINDOWS)
#define isnan _isnan
#define isinf !_finite
#endif

这是错误的。 _isnan_finite特定于Microsoft编译器。您是在 Windows 下编译的(因此定义了_WIN32WINDOWS),但您没有使用 Microsoft 编译器,因此这些关键字不存在。

注释掉此块应该允许您使用 MinGW 编译器编译 SPAMS 工具箱。(或者至少它可以防止您现在遇到的错误...

请注意,isnanisinf 是 C99 标准中定义的函数,没有必要为任何现代编译器定义这些宏。

最新更新