I am using Matlab 2018a and Microsoft Visual Studio 2017community which is compatible with Matlab 2018a, I wanted to use svmlin of Vikas Sindhwani(<http://vikas.sindhwani.org/svmlin.html)>. But when I execute "mex svmlin_mex.cpp ssl.o" command in the command window, the following errors appear: I tried with different compilers: 1-Building with 'MinGW64 Compiler with Windows 10 SDK or later (C++)'.:
2- Building with 'Microsoft Visual C++ 2017'.
3- Building with 'MinGW64 Compiler (C++)'.
What is the problem and how it can be overcome?

1 个评论

Please post the text as text, because reading the screenshots is very inconvenient.

请先登录,再进行评论。

 采纳的回答

Jan
Jan 2018-5-20
编辑:Jan 2018-5-20

0 个投票

The error messages are clear:
You try to store a mwIndex* in a int*, but you cannot expect, that they are compatible. The best solution is to define Data.colind with the correct type mwIndex*. The types int* and long long unsigned int* are simply different.
You would cause a crash, if your int* does not have the same width as mwIndex*. The sign matters also. So better rely on using correct types, even so it might "work" sometimes.

3 个评论

Thank you for your details, but how can I do that I do not know C++ very well.Can you help me with this. the main code is:
#include stdlib.h
#include stdio.h
#include ctype.h
#include "ssl.h"
#include "mex.h"
void parse_command_line(double* param);
struct options Options; struct data Data; struct vector_double Weights; struct vector_double Outputs;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
double *param;
fprintf(stdout, " SVM_lin (v1.0) (running thru Matlab)\n\n");
if (mxGetM(prhs[0]) != 7)
mexErrMsgTxt("Options vector must have 7 elements.");
if (nrhs < 3) {
mexErrMsgTxt("At least 4 input arguments required.");
}
param=mxGetPr(prhs[0]);
parse_command_line(param);
Data.colind = mxGetIr(prhs[1]);
Data.rowptr = mxGetJc(prhs[1]);
Data.val = mxGetPr(prhs[1]);
Data.n = mxGetM(prhs[1]);
Data.m = mxGetN(prhs[1]);
Data.nz= mxGetNzmax(prhs[1]);
if(nrhs==4)
{
Data.Y = mxGetPr(prhs[2]);
Data.C = mxGetPr(prhs[3]);
if (mxGetM(prhs[3]) != Data.m)
mexErrMsgTxt("Number of examples and costs do not match.");
if (mxGetM(prhs[2]) != Data.m)
mexErrMsgTxt("Number of examples and labels do not match.");
Data.u=0;
Data.l=0;
for(int i=0;i<Data.m;i++)
{
if (Data.Y[i]==0.0)
Data.u++;
else
Data.l++;
}
plhs[0]= mxCreateDoubleMatrix(Data.n,1,mxREAL);
double* w = mxGetPr(plhs[0]);
plhs[1]= mxCreateDoubleMatrix(Data.m,1,mxREAL);
double* o = mxGetPr(plhs[1]);
ssl_train(&Data,&Options,&Weights,&Outputs);
for(int i=0;i<Data.n;i++)
w[i]=Weights.vec[i];
for(int i=0;i<Data.m;i++)
o[i]=Outputs.vec[i];
delete[] Weights.vec;
delete[] Outputs.vec;
}
else
{
double *w = mxGetPr(prhs[4]);
if (mxGetM(prhs[4]) != Data.n)
mexErrMsgTxt("Number of features and weights do not match.");
plhs[0]= mxCreateDoubleMatrix(Data.m,1,mxREAL);
double *o = mxGetPr(plhs[0]);
double t;
int *ir = Data.rowptr;
int *jc = Data.colind;
double *pr = Data.val;
for(register int i=0; i < Data.m; i++)
{
t=0.0;
for(register int j=ir[i]; j < ir[i+1]; j++)
t+=pr[j]*w[jc[j]];
o[i]=t;
}
Outputs.d=Data.m;
Outputs.vec=new double[Data.m];
for(register int i=0; i < Data.m; i++)
Outputs.vec[i]=o[i];
if(mxGetM(prhs[2])>0) /* evaluate */
{
struct vector_double Labels;
Labels.vec = mxGetPr(prhs[2]);
Labels.d = mxGetM(prhs[2]);
ssl_evaluate(&Outputs,&Labels);
}
delete[] Outputs.vec;
}
}
void parse_command_line(double *param)
{
Options.algo = (int) param[0];
Options.lambda=param[1];
Options.lambda_u=param[2];
Options.S= (int) param[3];
Options.R= param[4];
Options.epsilon=EPSILON;
Options.cgitermax= (int) CGITERMAX;
Options.mfnitermax=(int) MFNITERMAX;
Options.Cp = param[5];
Options.Cn = param[6];
}
and this is the error:
Error using mex
svmlin_mex.cpp C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(29): error C2440: '=': cannot convert from 'mwIndex *' to 'int *'
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(29): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(30): error C2440: '=': cannot convert from 'mwIndex *' to 'int *'
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(30): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(32): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(33): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(34): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
C:\Users\au600166\Desktop\svmlin-v1.0\svmlin-v1.0\svmlin_mex.cpp(93): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data
Jan
Jan 2018-5-21
编辑:Jan 2018-5-21
You have to change the code, which defines the "struct data". This is one of the .h files you have included before. I strongly recommend not to do this, if you are not familiar with C, but to ask the author to fix the code.
Since I am not expert in C, I probably ask the author to update the code. thanks

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by