Linker error when creating Mex file
Show older comments
I am running Windows 7-64 bit with MatlabR2013a(64bit) using Microsoft VSC++2012. I am getting a linker error (LNK2019) when trying to create a mex file. I am using functions that are contained in a library file to which I have tried my best to tell the compiler where it is. I have no problem compiling and running my code in an environment outside Matlab.
I have tried every variation of:
mex foo.cpp thelibrary.lib ...
mex foo.cpp -l'thelibrary' -L'\thelibrarydirectory' ...
mex foo.cpp -lthelibrary -L\thelibrarydirectory ...
that I can think of, and none of them work. The error message that I get is pasted below. Any insight would be appreciated.
{
-> Default options filename found in C:\Users\David\AppData\Roaming\MathWorks\MATLAB\R2013a ---------------------------------------------------------------- -> Options file =
C:\Users\David\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat
MATLAB = C:\Program Files\MATLAB\R2013a
-> COMPILER = cl
-> Compiler flags:
COMPFLAGS = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD
OPTIMFLAGS = /O2 /Oy- /DNDEBUG
DEBUGFLAGS = /Z7
arguments = -I"C:\Program Files (x86)\Thorlabs\DCx Cameras\Develop\include"
Name switch = /Fo
-> Pre-linking commands =
-> LINKER = link
-> Link directives:
LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2013a\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\David\AppData\Local\Temp\mex_XumyOA\templib.x"
/MAP:"mqueryinfo.mexw64.map"
LINKDEBUGFLAGS = /debug /PDB:"mqueryinfo.mexw64.pdb"
LINKFLAGSPOST =
Name directive = /out:"mqueryinfo.mexw64"
File link directive =
Lib. link directive =
Rsp file indicator = @
-> Resource Compiler = rc /fo "mexversion.res"
-> Resource Linker =
----------------------------------------------------------------
--> cl -I"C:\Program Files (x86)\Thorlabs\DCx Cameras\Develop\include" /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\David\AppData\Local\Temp\mex_XumyOA\mqueryinfo.obj -I"C:\Program Files\MATLAB\R2013a\extern\include" -I"C:\Program Files\MATLAB\R2013a\simulink\include" /O2 /Oy- /DNDEBUG -DMX_COMPAT_32 mqueryinfo.cpp
mqueryinfo.cpp mqueryinfo.cpp(131) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning) mqueryinfo.cpp(132) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning) mqueryinfo.cpp(133) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning) mqueryinfo.cpp(134) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning) mqueryinfo.cpp(135) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning) mqueryinfo.cpp(34) : warning C4101: 'jstruct' : unreferenced local variable mqueryinfo.cpp(36) : warning C4101: 'ndim' : unreferenced local variable mqueryinfo.cpp(37) : warning C4101: 'tmp' : unreferenced local variable mqueryinfo.cpp(35) : warning C4101: 'NStructElems' : unreferenced local variable mqueryinfo.cpp(33) : warning C4101: 'classIDflags' : unreferenced local variable mqueryinfo.cpp(37) : warning C4101: 'fout' : unreferenced local variable c:\users\david\documents\thorlabs\matlab files\mqueryinfo.cpp(84) : warning C4700: uninitialized local variable 'nfields' used Contents of C:\Users\David\AppData\Local\Temp\mex_XumyOA\mex_tmp.rsp: C:\Users\David\AppData\Local\Temp\mex_XumyOA\mqueryinfo.obj uc480.lib
--> link /out:"mqueryinfo.mexw64" /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2013a\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\David\AppData\Local\Temp\mex_XumyOA\templib.x" /MAP:"mqueryinfo.mexw64.map" @C:\Users\David\AppData\Local\Temp\mex_XumyOA\mex_tmp.rsp "C:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft\uc480.lib"
Creating library C:\Users\David\AppData\Local\Temp\mex_XumyOA\templib.x and object C:\Users\David\AppData\Local\Temp\mex_XumyOA\templib.exp
mqueryinfo.obj : error LNK2019: unresolved external symbol __imp_is_InitCamera referenced in function mexFunction
mqueryinfo.obj : error LNK2019: unresolved external symbol __imp_is_ExitCamera referenced in function mexFunction
mqueryinfo.obj : error LNK2019: unresolved external symbol __imp_is_GetNumberOfCameras referenced in function mexFunction
mqueryinfo.obj : error LNK2019: unresolved external symbol __imp_is_GetSensorInfo referenced in function mexFunction
mqueryinfo.obj : error LNK2019: unresolved external symbol __imp_is_GetCameraList referenced in function mexFunction
mqueryinfo.mexw64 : fatal error LNK1120: 5 unresolved externals
C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'mqueryinfo.mexw64' failed.
Error using mex (line 206) Unable to complete successfully. }
EDIT: SOLVED when I specified a 64 bit library instead.
5 Comments
Kaustubha Govind
on 17 Jun 2013
Please add your solution as an "Answer" and accept it, so it is clear that this issue is resolved.
Camilla
on 29 Aug 2013
Hi David, I am having the same your problem. I am trying to call functions that are defined in a DLL but when I try to compile my main.cpp with matlab compiler I have the error LNK2019: unresolved external symbol
Were you able to solve the problem? If so, please let me know...I am having hard time with that!
Kaustubha Govind
on 29 Aug 2013
Camilla: David posted his solution at the bottom of his question, as an EDIT.
Camilla
on 30 Aug 2013
Thanks, I will try his solution immediately
George
on 10 Dec 2014
HOW and WHERE do you specify the 64-bit library?
Answers (0)
Categories
Find more on Windows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!