Why do I receive a link error when I try to use the lcc compiler to build my C MEX-file or MATLAB Compiler-generated shared library that includes a DLL compiled with MSVC?

4 views (last 30 days)
I have used the Microsoft Visual C++ IDE to develop and build a shared library (DLL). I was able to successfully build the DLL and corresponding import library, "myShLib.dll" and "myShLib.lib".
I then developed a C MEX-file (myMex.c) that uses symbols exported by the myShLib shared-library. Using MATLAB's "mex -setup" command, I then select lcc as the MEX C compiler, and try to build my C MEX-file using the MEX command, i.e.:
mex myMex.c myShLib.lib
I receive a link error originating from myMex.obj indicating that the symbols that are exported by myShLib are unresolved.
Note that I am confident that these particular symbols are exported, as I have verified that this is the case using Microsoft's DUMPBIN utility on myShLib.lib, as well as the Dependency Walker utility (<http://www.dependencywalker.com>) on myShLib.dll.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Nov 2016
This change has been incorporated into the documentation in Release 2011a (R2011a). For previous releases, read below for any additional information:
These link errors are caused by a binary incompatibility between Microsoft Visual C++ import libraries and lcc import libraries. The documentation for lcc notes that the Microsoft import library format is undocumented, and as such, Microsoft import libraries should not be used.
To use a Visual C++-generated DLL as part of an lcc build, use the lcc_implib.exe utility to create an lcc-compatible import library directly from the Visual C++ DLL by doing the following:
1. Add lcc's bin directory to the path with the following command at the system (DOS) command prompt:
path = %path%;<matlabroot>\sys\lcc\bin
where <matlabroot> denotes your MATLAB root directory, which can be found by entering "matlabroot" at the MATLAB Command Prompt.
2. Issue the following command at the system (DOS) command prompt to generate an lcc-compatible import library:
lcc_implib -u <libName>.dll
where <libName> refers to the name of the Visual C++-generated DLL.
3. Use the <libName>.lib file that was generated in step 2 for building the MEX project at the MATLAB Command Prompt:
mex <mexFile>.c <libName>.lib

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!