在Win10上为MATLAB编译SPAMS工具箱时出现错误“未声明'_finite'”

时间:2019-01-02 05:34:15

标签: matlab mex

我正在尝试使用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:\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{:});

1 个答案:

答案 0 :(得分:1)

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标准中定义的函数,对于任何现代编译器,都不必定义这些宏。