i use matlab 2013 x32 and visual studio 2008 sp1 but every time i get this fatal error.
LINK : error LNK2001: unresolved external symbol mexFunction
...mex_ZIBcNM\templib.x : fatal error LNK1120: 1 unresolved externals
D:\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'libqp_gsmo.mexw32' failed.

1 commentaire

Geoff Hayes
Geoff Hayes le 30 Déc 2014
Merve - please provide some context surrounding this error. What are you executing that result in this error message? If you are building a MEX file from the Command Window, then please include this statement.

Connectez-vous pour commenter.

 Réponse acceptée

merve
merve le 13 Jan 2015

0 votes

i reinstall matlab R2013a x64 (because my machine is x64) and install sdk 7.1(to do this remove all .net frameworks,sdk versions and any runtimes firstly).
then in the "mex-setup" i choose sdk7.1 (it is "[1] Microsoft Software Development Kit (SDK) 7.1 in C:\Program Files (x86)\Microsoft Visual Studio 10.0 " ).
in my folder i have two different source code: my pure c code(the function) and my mex function. i move this mex function into pure c code function.(do not forget to add #include "mex.h") and then It Works!
thanks for all answers and comments....

Plus de réponses (1)

Jan
Jan le 30 Déc 2014

1 vote

Does your source file contain a mexFunction definition?

5 commentaires

merve
merve le 31 Déc 2014
Modifié(e) : merve le 6 Jan 2015
ok i have to explain more detailed; actually i get some source files that i know that works fine and (i must change some part of these files) but firstly i just try to run these workin files on matlab. there is no incompatibility with the compiler because it works with another examples in matlab.
it contain a mexFunction definition in source file in libqp_gsmo_mex.c.
#include "mex.h"
#include "string.h"
#include "libqp_gsmo.c"
#define LIBQP_MATLAB
#include "libqp.h"
#define INDEX(ROW,COL,NUM_ROWS) ((COL*NUM_ROWS)+ROW)
#define MIN(A,B) ((A < B) ? A : B)
#define MAX(A,B) ((A > B) ? A : B)
double *mat_H;
uint32_t nVar;
const double *get_col( uint32_t i )
{
return( &mat_H[ nVar*i ] );
}
void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const mxArray*prhs[] )
{
int verb;
uint32_t i;
uint32_t MaxIter;
double TolKKT;
double *vec_x; /* output arg -- solution*/
double *vec_x0;
double *diag_H; /* diagonal of matrix H */
double *f; /* vector f */
double *a;
double b;
double *LB;
double *UB;
double fval;
libqp_state_T state;
/*------------------------------------------------------------------- */
/* Take input arguments */
/*------------------------------------------------------------------- */
if( nrhs != 10) mexErrMsgTxt("Incorrect number of input arguments.");
mat_H = mxGetPr(prhs[0]);
nVar = mxGetM(prhs[0]);
f = mxGetPr(prhs[1]);
a = mxGetPr(prhs[2]);
b = mxGetScalar(prhs[3]);
LB = mxGetPr(prhs[4]);
UB = mxGetPr(prhs[5]);
vec_x0 = mxGetPr(prhs[6]);
MaxIter = mxIsInf( mxGetScalar(prhs[7])) ? INT_MAX : (long)mxGetScalar(prhs[7]);
TolKKT = mxGetScalar(prhs[8]);
verb = (int)(mxGetScalar(prhs[9]));
if( verb > 0 ) {
mexPrintf("Settings of QP solver\n");
mexPrintf("MaxIter : %d\n", MaxIter );
mexPrintf("TolKKT : %f\n", TolKKT );
mexPrintf("nVar : %d\n", nVar );
mexPrintf("verb : %d\n", verb );
}
plhs[0] = mxCreateDoubleMatrix(nVar,1,mxREAL);
vec_x = mxGetPr(plhs[0]);
memcpy( vec_x, vec_x0, sizeof(double)*nVar );
diag_H = mxCalloc(nVar, sizeof(double));
if( diag_H == NULL ) mexErrMsgTxt("Not enough memory.");
for(i = 0; i < nVar; i++ )
diag_H[i] = mat_H[nVar*i+i];
/*------------------------------------------------------------------- */
/* Call QP solver */
/*------------------------------------------------------------------- */
state = libqp_gsmo_solver( &get_col, diag_H, f, a, b, LB, UB, vec_x,
nVar, MaxIter, TolKKT, NULL );
/*------------------------------------------------------------------- */
/* Generate outputs */
/*------------------------------------------------------------------- */
plhs[1] = mxCreateDoubleScalar(state.QP);
plhs[2] = mxCreateDoubleScalar((double)state.exitflag);
plhs[3] = mxCreateDoubleScalar((double)state.nIter);
/*------------------------------------------------------------------- */
/* Clean up */
/*------------------------------------------------------------------- */
mxFree( diag_H );
}
/* EOF */
if true
% code
end
Hi Merve,
I hope the missing space in
const mxArray*prhs[]
is copy paste error?
Titus
Titus Edelhofer
Titus Edelhofer le 6 Jan 2015
Hi Merve,
I just tried your function (commenting out all libqp stuff). Worked fine. Please compile using "-v" to see if something else went wrong before ...
Titus
merve
merve le 6 Jan 2015
Modifié(e) : merve le 7 Jan 2015
after compiling -v it says; Contents of C:\Users\lenovo\AppData\Local\Temp\mex_7Jd3gr\mex_tmp.rsp: C:\Users\lenovo\AppData\Local\Temp\mex_7Jd3gr\libqp_gsmo.obj
.obj file is in my current folder on matlab but it is not exist in C:\Users\lenovo\AppData\Local\Temp\mex_7Jd3gr\
thanks for help
Titus Edelhofer
Titus Edelhofer le 7 Jan 2015
In this case you should (re-)run "mex -setup" to configure the mex options.
Titus

Connectez-vous pour commenter.

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by