mexFuncion.obj : error LNK2019: unresolved external symbol _mxGetPr referenced in function _mexFunction
18 views (last 30 days)
Show older comments
Hi, I am learning how to interface matlab with c++, I am following a simple example, "timestwo.c", in matroot/extern/examples/refbook/,
#include "mex.h" #pragma comment(lib,"libmx.lib")
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmex.lib")
void timestwo(double y[], double x[]) { y[0] = 2.0*x[0]; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { double *x,*y; mwSize mrows,ncols;
/* Check for proper number of arguments. */
if(nrhs!=1) {
mexErrMsgTxt("One input required.");
} else if(nlhs>1) {
mexErrMsgTxt("Too many output arguments.");
}
/* The input must be a noncomplex scalar double.*/
mrows = mxGetM(prhs[0]);
ncols = mxGetN(prhs[0]);
if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) ||
!(mrows==1 && ncols==1) ) {
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
/* Create matrix for the return argument. */
plhs[0] = mxCreateDoubleMatrix(mrows,ncols, mxREAL);
/* Assign pointers to each input and output. */
x = mxGetPr(prhs[0]);
y = mxGetPr(plhs[0]);
/* Call the timestwo subroutine. */
timestwo(y,x);
}
i was able to compile it in Microsoft visual C++ 2010 successfully, but when I build it, i get linking errors as follows,
mexFuncion.obj : error LNK2019: unresolved external symbol _mxGetPr referenced in function _mexFunction mexFuncion.obj : error LNK2019: unresolved external symbol _mxCreateDoubleMatrix_730 referenced in function _mexFunction mexFuncion.obj : error LNK2019: unresolved external symbol _mxIsComplex referenced in function _mexFunction mexFuncion.obj : error LNK2019: unresolved external symbol _mxIsDouble referenced in function _mexFunction mexFuncion.obj : error LNK2019: unresolved external symbol _mxGetN referenced in function _mexFunction mexFuncion.obj : error LNK2019: unresolved external symbol _mxGetM referenced in function _mexFunction mexFuncion.obj : error LNK2019: unresolved external symbol _mexErrMsgTxt referenced in function _mexFunction
I think linkers cannot found library such as "libmx.lib" libmat.lib" libmex.lib", but i set the path mathroot\extern\lib\win64\microsoft under the the project->property->linker->general->additional library directories. In addition, i have a mexFunction.def as follows: LIBRARY “My_project" EXPORTS mexFunction
where else could be missing for those errors?
0 Comments
Answers (1)
Friedrich
on 18 Jul 2011
Hi,
you have to set some more. I created a MSVC timestwo.c example and uploaded it here:
2 Comments
Friedrich
on 18 Jul 2011
Hi,
I used VS 2008. You have to modify the path in the project settings so they match your system and installation of your ML.
1.) Under C/C++ ->gernal -> additional include dirs: MATLABROOT\extern\include
2.) Under Linker -> general -> additional lib dirs you have to add the libraries directory: MATLABROOT\extern\lib\win32\microsoft
3.)Under Linker -> Input -> additional dependencies you have to add:
libmx.lib libmex.lib libmat.lib
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!