在 Win10 上为 MATLAB 编译 SPAMS 工具箱时出现错误 "undeclared '_finite'"

Error "undeclared '_finite'" when compiling the SPAMS toolbox for MATLAB on Win10

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

当我运行 compile.m时出现错误,似乎某些functions/modules(我不确定如何称呼它们)可以编译而其他的则不能。我试图评论那些导致错误的函数(大约一半的函数),其余的 运行 很好,但它们无法通过 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:\xm\data\SPAMS\spams-matlab-v2.6-2017-02-27\spams-matlab-v2.6\dictLearn\mex\mexStructTrainDL.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:\xm\data\SPAMS\spams-matlab-v2.6-2017-02-27\spams-matlab-v2.6\dictLearn\mex\mexStructTrainDL.cpp:268:7:   required from 'void callFunction(mxArray**,
const mxArray**, int, int) [with T = double; mxArray = mxArray_tag]'
E:\xm\data\SPAMS\spams-matlab-v2.6-2017-02-27\spams-matlab-v2.6\dictLearn\mex\mexStructTrainDL.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:\xm\data\SPAMS\spams-matlab-v2.6-2017-02-27\spams-matlab-v2.6\dictLearn\mex\mexStructTrainDL.cpp:268:7:   required from 'void callFunction(mxArray**,
const mxArray**, int, int) [with T = float; mxArray = mxArray_tag]'
E:\xm\data\SPAMS\spams-matlab-v2.6-2017-02-27\spams-matlab-v2.6\dictLearn\mex\mexStructTrainDL.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{:});

在 SPAMS 附带的文件 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 标准中定义的函数,对于任何现代编译器都没有必要定义这些宏。