Why do I receive link errors (LNK2019) when compiling in Microsoft Visual C++ 2005?
4 views (last 30 days)
Show older comments
I use MATLAB Compiler to build a C++ shared library "libmatrixp.dll". When I build the driver "matrixdriver.cpp" in Microsoft Visual C++ 2005, after properly setting the link and include paths, I receive link errors:
1>------ Build started: Project: matrixtest, Configuration: Debug Win32------
1>Compiling...
1>matrixdriver.cpp
1>Compiling manifest to resources...
1>Linking...
1>matrixdriver.obj : error LNK2019: unresolved external symbol
_mclTerminateApplication referenced in function
__catch$?run_main@@YAPAXPAX@Z$0
1>matrixdriver.obj : error LNK2019: unresolved external symbol
_libmatrixpTerminate referenced in function
__catch$?run_main@@YAPAXPAX@Z$0
1>matrixdriver.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void __cdecl eigmatrix(int,class mwArray &,class
mwArray const &)" (__imp_?eigmatrix@@YAXHAAVmwArray@@ABV1@@Z) referenced
in function "void * __cdecl run_main(void *)" (?run_main@@YAPAXPAX@Z)
1>matrixdriver.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void __cdecl multiplymatrix(int,class mwArray
&,class mwArray const &,class mwArray const &)"
(__imp_?multiplymatrix@@YAXHAAVmwArray@@ABV1@1@Z) referenced in function
"void * __cdecl run_main(void *)" (?run_main@@YAPAXPAX@Z)
1>matrixdriver.obj : error LNK2019: unresolved external symbol
"__declspec(dllimport) void __cdecl addmatrix(int,class mwArray &,class
mwArray const &,class mwArray const &)"
(__imp_?addmatrix@@YAXHAAVmwArray@@ABV1@1@Z) referenced in function
"void * __cdecl run_main(void *)" (?run_main@@YAPAXPAX@Z)
1>matrixdriver.obj : error LNK2019: unresolved external symbol
_libmatrixpInitialize referenced in function "void * __cdecl
run_main(void *)" (?run_main@@YAPAXPAX@Z)
1>matrixdriver.obj : error LNK2019: unresolved external symbol
_mclInitializeApplication referenced in function "void * __cdecl
run_main(void *)" (?run_main@@YAPAXPAX@Z)
Accepted Answer
MathWorks Support Team
on 27 Jun 2009
These are the linking errors caused when the compiler tries to link your application with the appropriate libraries that define all the symbols. Just providing the path to these libraries (lib files) is not enough. You will need to add them manually to your Visual Studio project in order to resolve all the symbols.
In order to include the required libraries, you will need to add them under Project -> Properties -> Linker -> Input -> Additional dependencies:
For example: mclmcrrt.lib, mclmcr.lib, libmatrixp.lib (see included screen shot).
So when getting this type of linking errors, try to identify the function (symbol) that cannot be resolved and see which library it belongs to, then add the library to the linker list as explained above. To identify the function, search your source code for its name, for example mclTerminateApplication. Then right click on the function and click on "Go To Definition". If all path settings are set right, this will open the file mclmcrrt.h, this will tell you that you need to add the mclmcrrt.lib file to the linker list.
If you are compiling using the MATLAB MBUILD command and get this type of error, try to identify the library that contains the missing symbols as explained above and add the library to the MBUILD command.
0 Comments
More Answers (0)
See Also
See Also
Categories
Find more on Deploy to C++ Applications Using mwArray API (C++03) 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!