MATLAB Answers

1

MEX error LNK2019: unresolved external symbol

Asked by maarten vaandrager on 8 Jan 2014
Latest activity Commented on by Ingo Hermann on 8 Nov 2017
Hi everybody,
I need to fix a matlab program that incorporates C code compiled to a mex function. It is likely that the mex functions stopped working when updating Matlab from 32bit to 64bit.
when trying to recompile the c code into a mex file I get the following error:
mex qpip.c
qpip.obj : error LNK2019: unresolved external symbol qpip_sub referenced in function mexFunction
qpip.obj : error LNK2019: unresolved external symbol dcopy referenced in function mexFunction
qpip.mexw64 : fatal error LNK1120: 2 unresolved externals
I did not write the program myself but I should have all the necessary files. The qpip_sub.c and qpip_sub.h and some other files are in the same folder. The dcopy function seems to be part of the the BLAS linear algebra package but I only seem to have blasmap.h.
Any ideas what is going wrong? Thanks for the help!
(using MSVS2010, MATLAB R2011b, 64bit Windows 7)

  0 Comments

Sign in to comment.

Products

2 Answers

Answer by Jorik
on 9 Jan 2014
Edited by Jorik
on 9 Jan 2014
 Accepted Answer

The unresolved external symbols errors indicate that during the link-stage of compiling the MEX-file, these symbols are not available.
For the qpip_sub, this most probably means, you need to add the source-file with that function to the MEX command.
For the dcopy (a BLAS function?), this most probably means, you want to link to the BLAS library that is shipping with MATLAB, see this documentation page for more information regarding compiling MEX-files that use BLAS functions.

  3 Comments

Hi Jorik,
if I execute
mex qpip.c qpip_sub.c
I get different errors but all only related to the blas library. So you are right with your first remark that I need to compile all the source files in one command.
I'll read the documentation page about BLAS and let you know if this solves the other linking problems.
Problem solved :) As explained in the documentation I needed to add the BLAS and LAPACK libraries that come with matlab to the mex command:
location = 'C:\Program Files\MATLAB\R2011b\extern\lib\win64\microsoft\';
lapacklib = [location 'libmwlapack.lib'];
blaslib = [location 'libmwblas.lib'];
mex('-v', '-largeArrayDims', 'qpip.c','qpip_sub.c', blaslib, lapacklib)
Thanks a lot Jorik!
Compiling all the files in one command helped me - thank you!

Sign in to comment.


Answer by Ingo Hermann on 8 Nov 2017

I have a similar problem with the error:
mex mexFitFunctions.c
Building with 'Microsoft Windows SDK 7.1 (C)'.
Error using mex
LINK : error LNK2001: unresolved external symbol mexFunction
mexFitFunctions.lib : fatal error LNK1120: 1 unresolved externals
I tried the stuff from aboth but get the same error.

  1 Comment

And my real problem is in that mex file:
Building with 'Microsoft Windows SDK 7.1 (C)'.
cl /c /GR /W3 /EHs /nologo /MD -I"(D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\levmar-2.6)" -I"(D:\IngoHermann\MATLAB\external\include)" -I"(D:\IngoHermann\MATLAB\simulink\include)" /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /USE_LIBCMT=0 /Z7 D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\mexT1Mapping.c /FoC:\Users\ih11\AppData\Local\Temp\mex_193841985824822_4328\mexT1Mapping.obj
mexT1Mapping.c
D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\mexT1Mapping.c(49) : warning C4013: 'strcmp' undefined; assuming extern returning int
cl /c /GR /W3 /EHs /nologo /MD -I"(D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\levmar-2.6)" -I"(D:\IngoHermann\MATLAB\external\include)" -I"(D:\IngoHermann\MATLAB\simulink\include)" /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /USE_LIBCMT=0 /Z7 D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\mexFitFunctions.c /FoC:\Users\ih11\AppData\Local\Temp\mex_193841985824822_4328\mexFitFunctions.obj
mexFitFunctions.c
d:\ingohermann\matlab\t1tool\t1recotool\mexresources\mexfitfunctions.c(289) : warning C4789: destination of memory copy is too small
cl /c /GR /W3 /EHs /nologo /MD -I"(D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\levmar-2.6)" -I"(D:\IngoHermann\MATLAB\external\include)" -I"(D:\IngoHermann\MATLAB\simulink\include)" /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /USE_LIBCMT=0 /Z7 D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\mexUtils.c /FoC:\Users\ih11\AppData\Local\Temp\mex_193841985824822_4328\mexUtils.obj
mexUtils.c
link /nologo /manifest /DLL /debug /PDB:"mexT1Mapping.mexw64.pdb" /EXPORT:mexFunction C:\Users\ih11\AppData\Local\Temp\mex_193841985824822_4328\mexT1Mapping.obj C:\Users\ih11\AppData\Local\Temp\mex_193841985824822_4328\mexFitFunctions.obj C:\Users\ih11\AppData\Local\Temp\mex_193841985824822_4328\mexUtils.obj D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\levmar-2.6\levmar.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\clapack.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\BLAS.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\BLAS_nowrap.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\libf2c.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\f77blaswrap.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\cblaswrap.lib D:\IngoHermann\MATLAB\T1Tool\T1RecoTool\MexResources\CLAPACK\lib\x64\tmglib.lib /LIBPATH:"D:\IngoHermann\MATLAB\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /out:mexT1Mapping.mexw64
Error using mex
Creating library mexT1Mapping.lib and object mexT1Mapping.exp
mexT1Mapping.obj : error LNK2019: unresolved external symbol maxAbsArray referenced in function threadFunc
mexFitFunctions.obj : error LNK2019: unresolved external symbol dlevmar_der referenced in function wrapFunctionT2
mexFitFunctions.obj : error LNK2019: unresolved external symbol dlevmar_dif referenced in function
wrapFunctionSASHA
mexFitFunctions.obj : error LNK2019: unresolved external symbol minAbsArray referenced in function
wrapFunctionSAPPHIREPre
mexFitFunctions.obj : error LNK2019: unresolved external symbol dlevmar_bc_der referenced in function
wrapFunctionShMOLLI
mexT1Mapping.mexw64 : fatal error LNK1120: 5 unresolved externals

Sign in to comment.