I would like to include version information with my DLL. I am compiling the DLL in MATLAB using the MCC command and the LCC Compiler.
MATLAB: How to specify version information for a DLL compiled using MATLAB Compiler when set up with LCC
appdllslibMATLAB Compilermbuild
Related Solutions
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
The ability to add custom icons natively in a compiled application is available in the deploytool with release R2013b.
This is not possible in releases R2010b - R2013a.
If you are using MATLAB compiler 4.13 (R2010a) or before see below for any workarounds:
There are two ways to include a custom icon in a compiled application. One way is to modify the icon after the EXE has been generated using 3rd party software. The other way is to include the icon at compile time using a resource file. Each of these is explained further below.
1. In order to associate an icon with an application after the EXE has been created, you will need to use a 3rd party tool to modify the icon. There are many applications available for this purpose. A good place to start is by searching the "Downloads" area of some popular sites like https://www.pcworld.com/ and https://www.cnet.com/ .
2. If you wish to include the icon at compile time, you will need to make sure that your compiler supports this. The general process is to create a resource file which points to the icon, compile it with a resource compiler, and then include the compiled resource file when compiling the application.
Steps for MSVC Compiler:
1. Create a new Win32 Console Application
2. Right-click on "Resource Files" then select "Add->New Item"
3. In the new window, under "Visual C++", select "Resource"
4. Then in the "Visual Studio installed templates" section, select "Resource File (.rc)"
5. Specify a name for the resource file and click on "Add"
6. Right-click on "Resource Files" again and choose "Add Resource"
7. Select "Icon" and click "New"
8. Create the icon
9. Build the solution (F7)
10. Copy the generated .res file to the folder with the MATLAB code
11. Compile the MATLAB code:
mcc -m myfile.m -M icon.res
where icon.res is the compiled resource file. You can use the "-M" flag to specify compile-time options to your specific compiler. Type
doc mcc
for more information about this flag. These steps may vary depending on which version of Microsoft Visual Studio you are using. If you are not using a Microsoft compiler, you may want to see if your 3rd party compiler supports icon files.
Steps for LCC Compiler:
1. Let the icon file be named 'ship.ico'. If you have an image file (*.JPEG, *.TIFF, *.GIF, *.PNG...), you will need to use a 3rd party tool (you can search online for an image converter) to convert your image to a .ICO icon file.
2. Create a new text file and write "ConApp ICON ship.ico" in it. Rename it as "example.rc" and save it in your current directory.
3. Compile "example.rc" and "ship.ico" files using the following command at MATLAB prompt:
system(['"' matlabroot '\sys\lcc\bin\lrc" /i "' pwd '\example.rc"']);
After this step you will have a resource file "example.res" created in your working directory.
4. Compile the MATLAB files and the resource file together using the -M option as before:
mcc -m file1.m -M example.res
where file1.m can be any MATLAB File you want to deploy. This will create a "file1.exe" in your working directory with the same icon as "ship.ico".
If you are using MATLAB compiler 4.14 (R2010b) then see below:
Steps for MSVC Compiler:
Here instead of creating a '.exe' file, you will need to create a C shared library and write wrapper driver code that calls the main function of the application. More information about this can be found in the link below.
http://www.mathworks.com/help/releases/R2010a/toolbox/compiler/f13-1001757.html
A custom icon can then be associated with the EXE that is created when the driver code is compiled. For the sample driver code we are using FIGURETEST as the MATLAB function compiled into LIBFIGURE.DLL. Please follow the steps below once your DLL is created:
1. Create the C shared library using the link above.
2. Create a new Win32 Console Application named "test".
3. Right-click on "Resource Files" then select "Add->New Item"
4. In the new window, under "Visual C++", select "Resource"
5. Then in the "Visual Studio installed templates" section, select "Resource File (.rc)"
6. Specify a name for the resource file and click on "Add"
7. Right-click on "Resource Files" again and choose "Add Resource"
8. Select "Icon" and click "New"
9. Create the icon
10. Build the solution (F7)
11. Write your driver code in test.cpp and compile the VC++ console application by correctly providing the path to your library. Sample driver code is as follows.
// test.cpp : Defines the entry point for the console application.// libfigure is the Shared Library// Figuretest() is the main function in the library which corresponds to the // figuretest() function in the .m file which was compiled using mcc#include "stdafx.h"#include <libfigure.h>int _tmain(int argc, _TCHAR* argv[]){// Have to find out the pathsif( !mclInitializeApplication(NULL,0) ) { fprintf(stderr, "Could not initialize the application.\n"); return -1; }// Initialize the libraryif (!libfigureInitialize()){ fprintf(stderr,"Could not initialize the library.\n"); return -2; }else{//Call the figure librarymlfFiguretest();mclWaitForFiguresToDie(NULL);printf("Success");// TerminatelibfigureTerminate();mclTerminateApplication();}return 0;}
Steps for LCC Compiler:
There are no workarounds other than using third party products to insert the icon after compiling the application.
Best Answer