MATLAB Answers

0

Why do I receive link errors (LNK2019) when compiling in Microsoft Visual C++ 2005?

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)

Products


Release

R2008a

2 Answers

Answer by MathWorks Support Team on 27 Jun 2009
 Accepted Answer

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

Sign in to comment.


Answer by Ashwin
on 30 Jan 2015

I used the suggested recipe but I am still having the linking error.

I am using MATLAB Compiler 2014b and Microsoft Visual C++ 2013 which seems supported (<http://uk.mathworks.com/support/compilers/R2014b/index.html)>.

Any idea of how to sort it out?

  1 Comment

Hi Ashwin, can you send a support request to support@mathworks.com with this information? Thanks!

Sign in to comment.