Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Mex error- LNK2019: unresolved external symbol, but linked library seems to be detected

Subject: Mex error- LNK2019: unresolved external symbol, but linked library seems to be detected

From: Prasad

Date: 13 Dec, 2012 09:30:09

Message: 1 of 2

I can't seem to link the kinect10 library to my mex code.

I am trying to interface some Kinect C++ code that I wrote into matlab, and all I want to do right now is test to see if the kinect initializes connection in matlab through mex, using the following code (connect.cpp):

#include<Windows.h>
#include"NuiApi.h"
#include "mex.h"

int x;
HRESULT hr;

int connect(){
hr = NuiInitialize( NUI_INITIALIZE_FLAG_USES_SKELETON);
  
if( FAILED( hr ) )
  {
   // printf ("Kinect has not been initialized, uh oh.\n");
    return 0;
  }else{
// printf("The kinect has initialized. \n");
      return 1;
  }

}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    double *y;
    
    y = mxGetPr(plhs[0]);
    y[0]= connect();
    
    return;
}


The NuiApi.h is located in the same directory as the connect.cpp file. I have placed one library file that contains the 'Kinect10.lib' file in several directories including the working directory.

This is the command used to compile connect.cpp:

mex -v connect.cpp -lKinect10


This is my output (not all of it):
connect.cpp
    Contents of C:\Users\pt2091\AppData\Local\Temp\mex_EWS0Sl\mex_tmp.rsp:
  C:\Users\pt2091\AppData\Local\Temp\mex_EWS0Sl\connect.obj
 
 
--> link /out:"connect.mexw64" /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2012a\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\pt2091\AppData\Local\Temp\mex_EWS0Sl\templib.x" /MAP:"connect.mexw64.map" @C:\Users\pt2091\AppData\Local\Temp\mex_EWS0Sl\mex_tmp.rsp "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\LIB\amd64\Kinect10.lib"
 
   Creating library C:\Users\pt2091\AppData\Local\Temp\mex_EWS0Sl\templib.x and object C:\Users\pt2091\AppData\Local\Temp\mex_EWS0Sl\templib.exp
connect.obj : error LNK2019: unresolved external symbol __imp_NuiInitialize referenced in function "int __cdecl connect(void)" (?connect@@YAHXZ)
connect.mexw64 : fatal error LNK1120: 1 unresolved externals
 
  C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Link of 'connect.mexw64' failed.
 

Is there something i'm completely missing?

Subject: Mex error- LNK2019: unresolved external symbol, but linked library seems to be detected

From: James Tursa

Date: 13 Dec, 2012 17:26:09

Message: 2 of 2

"Prasad " <pt2091@gmail.com> wrote in message <kac771$60k$1@newscl01ah.mathworks.com>...

(snip)

> void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
> {
> double *y;
>
> y = mxGetPr(plhs[0]);
> y[0]= connect();
>
> return;
> }

The above mxGetPr(plhs[0]) call will bomb MATLAB since plhs[0] doesn't exist (you haven't created it yet). You need to create plhs[0] before using it. E.g., add this as your first line:

    plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);

then you can go get the data pointer with mxGetPr(plhs[0]). Or, more simply, you could replace all of the above with one line:

    plhs[0] = mxCreateDoubleScalar(connect());

> The NuiApi.h is located in the same directory as the connect.cpp file. I have placed one library file that contains the 'Kinect10.lib' file in several directories including the working directory.
>
> This is the command used to compile connect.cpp:
>
> mex -v connect.cpp -lKinect10

Since Kinect10.lib is already in your working directory, try explicitly including it in the mex command. E.g.,

    mex -v connect.cpp Kinect10.lib


James Tursa

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us