mex function error LNK2019: unresolved external symbol

2 Ansichten (letzte 30 Tage)
Marcus
Marcus am 13 Feb. 2014
Hi,
I am trying to compile mex code and I am receiving a link error. I know I need to add additional source/lib/dll file(s) to the compile command but I am not sure what files to add. The link error is due to a functional call in the code (joyGetPos) but when I go to the function it exists solely in a header file. I can't find source code associated with the function or a lib/dll to reference.
Here is the code: #include mex.h #define WIN32_LEAN_AND_MEAN #define WINVER 0x0500 #include windows.h #include mmsystem.h
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int joyId; JOYINFO joyInfo; mwSize sizePos[] = {3,1}; mwSize sizeBut[] = {16,1}; double *pos; double *but; int i;
if (nlhs != 2 || nrhs != 1 || mxIsEmpty(prhs[0]) || mxGetNumberOfElements(prhs[0]) != 1 || (joyId = (int) mxGetPr(prhs[0])[0]) < 0 || joyId > 15) {
mexErrMsgTxt("Usage: [position, buttons] = mat_job(joystick_id), where:\n\njoystick_id - joystick identifier (0-15),\nposition - list of joystick position in X, Y and Z axis,\nbuttons - list of 16 joystick button states (missing buttons are always zeros)");
}
joyGetPos(joyId, &joyInfo);
plhs[0] = mxCreateNumericArray(2, sizePos, mxDOUBLE_CLASS, mxREAL);
plhs[1] = mxCreateNumericArray(2, sizeBut, mxDOUBLE_CLASS, mxREAL);
pos = mxGetPr(plhs[0]);
but = mxGetPr(plhs[1]);
pos[0] = ((double) joyInfo.wXpos - 32767) / 32767;
pos[1] = ((double) joyInfo.wYpos - 32767) / 32767;
pos[2] = ((double) joyInfo.wZpos - 32767) / 32767;
for(i = 0; i < 16; i++) {
but[i] = (joyInfo.wButtons >> i) & 1;
}
}
Here is the command with error: mex matJoystick.cpp Creating library C:\Users\MRAHIM~1\AppData\Local\Temp\mex_44U_2Q\templib.x and object C:\Users\MRAHIM~1\AppData\Local\Temp\mex_44U_2Q\templib.exp matJoystick.obj : error LNK2019: unresolved external symbol _imp_joyGetPos@8 referenced in function _mexFunction matJoystick.mexw32 : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: Link of 'matJoystick.mexw32' failed.
Error using mex (line 206) Unable to complete successfully.

Antworten (1)

Vignesh Rangaishenvi
Vignesh Rangaishenvi am 16 Jun. 2014
Try compiling the mex code using the -I option (by including the path to the header file) with the mex command. Refer to using mex files on using the -I option with mex.
The -I option is used to specify the path to include the MATLAB LAPACK library subroutines for handling complex number routines. If you want to use functions from a library, you can use the -L option with mex instead.

Kategorien

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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by