Trying to compile C++ Source Code for Matlab. Issue with name function definition/modification.

8 Ansichten (letzte 30 Tage)
Hi,
I use Matlab2019b. I've been trying to compile on Windows an optimization toolbox called SPAMS http://spams-devel.gforge.inria.fr/index.html. The source code is in c++.
A compile.m file is provided, which helps the compilation procedure. An example command produced by the script is the following:
mex -IC:\Users\spams-matlab-v2.6\linalg -IC:\Users\spams-matlab-v2.6\decomp decomp\mex\mexLasso.cpp -outdir ./build/ -DUSE_BLAS_LIB -DNEW_MATLAB_BLAS -DINT_64BITS -largeArrayDims -DNDEBUG -DWINDOWS -DREMOVE_ -LC:\"Program Files"\MATLAB\R2019b\extern\lib\win64\microsoft\libmwblas.lib -LC:\"Program Files"\MATLAB\R2019b\extern\lib\win64\microsoft\libmwlapack.lib OPTIMFLAGS=" -O"
This is repeated for the different .cpp files in the toolbox.
However the commands work only for some of the libraries.
For some others I get errors similar to this:
Error using mex
In file included from C:\Users\ucacmgu\Documents\spams-matlab-v2.6\decomp\mex\mexLasso.cpp:34:0:
C:\Users\spams-matlab-v2.6\decomp/decomp.h: In instantiation of 'void coreLARS(Vector<T>&,
Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Vector<T>&, Matrix<T>&, Matrix<T>&, Matrix<T>&,
Matrix<T>&, Matrix<T>&, Matrix<T>&, const AbstractMatrix<T>&, T&, Vector<long long int>&, Vector<T>&, T, bool,
bool, constraint_type, T*, int) [with T = double]':
C:\Users\spams-matlab-v2.6\decomp/decomp.h:819:15: required from 'void lasso(const
Data<T>&, const AbstractMatrix<T>&, const AbstractMatrix<T>&, SpMatrix<T>&, int, T, constraint_type, bool,
bool, int, Matrix<T>*, int) [with T = double]'
C:\Users\spams-matlab-v2.6\decomp\mex\mexLasso.cpp:179:21: required from 'void
callFunction(mxArray**, const mxArray**, int, int) [with T = double; mxArray = mxArray_tag]'
C:\Users\spams-matlab-v2.6\decomp\mex\mexLasso.cpp:216:50: required from here
C:\Users\spams-matlab-v2.6\decomp/decomp.h:1026:28: error: 'isnan_' was not declared in this
scope
if (t > 0 || isnan(t) || isinf(t)) {
C:\Users\ucacmgu\Documents\spams-matlab-v2.6\decomp/decomp.h:1026:40: error: 'finite_' was not declared in
this scope
if (t > 0 || isnan(t) || isinf(t)) {
I found that the isnan and isinf functions in the error are defined in a header file included in the .cpp files. This is the initial part of the header (misc.h):
#ifndef MISC_H
#define MISC_H
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include "utils.h"
#if defined(_MSC_VER) || defined(_WIN32) || defined(WINDOWS)
#define isnan _isnan
#define isinf !_finite
#endif
using namespace std;
Really don't know where the error is.
Please help me!
Michele
  4 Kommentare
James Tursa
James Tursa am 29 Jan. 2021
Bearbeitet: James Tursa am 29 Jan. 2021
But where in decomp.h is the isnan and isinf stuff?
Michele Guerreri
Michele Guerreri am 30 Jan. 2021
Here is the specific part of the code:
if (ols == 0) {
const T t = gamma*gamma - 2*gamma*potentNorm;
if (t > 0 || isnan(t) || isinf(t)) {
// cerr << "bad bad exit" << endl;
// cerr << t << endl;
ind[j]=-1;
break;
}
normX += t;
} else {
// plan the last orthogonal projection
if (newAtom) {
RUn[j]=0.0;
for (int k = 0; k<=j; ++k) RUn[j] += Xdn[ind[k]]*
Un[j*L+k];
normX -= RUn[j]*RUn[j];
}
}
decomp.h is 3000+ lines of code. I've attached the file here for complitness.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Write C Functions Callable from MATLAB (MEX Files) finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by