matlablinker-errorsmexlnk2019lnk2001

Error using mex (line 206) Unable to complete successfully


I am trying to compile cpp files from this link, but I am receiving the following errors:

>> mex OpticalFlow.cpp

LINK : error LNK2001: unresolved external symbol mexFunction   
C:\Users\pc\AppData\Local\Temp\mex_Fe1hah\templib.x :   
fatal error LNK1120: 1 unresolved externals    
E:\MATLAB2\R2013A\BIN\MEX.PL: Error: Link of 'OpticalFlow.mexw32' failed. 

>> mex GaussianPyramid.cpp

LINK : error LNK2001: unresolved external symbol mexFunction  
C:\Users\pc\AppData\Local\Temp\mex_IWT6TB\templib.x : fatal error LNK1120: 1 unresolved externals  
E:\MATLAB2\R2013A\BIN\MEX.PL: Error: Link of 'GaussianPyramid.mexw32' failed.   
Creating library C:\Users\pc\AppData\Local\Temp\mex_5guviT\templib.x and object  C:\Users\pc\AppData\Local\Temp\mex_5guviT\templib.exp  
Coarse2FineTwoFrames.obj : error LNK2019: unresolved external symbol "public: static void __cdecl OpticalFlow::Coarse2FineFlow(class Image<double> &,class Image<double> &,class Image<double> &,class Image<double> const &,class Image<double> const &,double,double,int,int,int,int)" (?Coarse2FineFlow@OpticalFlow@@SAXAAV?$Image@N@@00ABV2@1NNHHHH@Z) referenced in function _mexFunction  
Coarse2FineTwoFrames.mexw32 : fatal error LNK1120: 1 unresolved externals   
E:\MATLAB2\R2013A\BIN\MEX.PL: Error: Link of 'Coarse2FineTwoFrames.mexw32' failed.   
Error using mex (line 206)  
Unable to complete successfully.  

Can somebody help me, please?


Solution

  • The package you are trying to compile consists of three cpp files, but they should be compiled into a single mex file.
    as a result they only have one mexFunction symbol defined in them.
    Try

    >> mex -O -largeArrayDims Coarse2FineTwoFrames.cpp GaussianPyramid.cpp OpticalFlow.cpp