How can I specify version information for including in a DLL or an EXE generated with MATLAB Coder or Simulink Coder?

4 views (last 30 days)

I would like to include version information when generating a DLL or an EXE with MATLAB Coder or Simulink Coder. This version information can be found when inspecting the properties of the DLL/EXE in Windows Explorer.
How can I include version information when using MATLAB Coder? Is there any difference for Simulink Coder?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Sep 2024
It is possible to add metadata to a Windows binary built with MATLAB Coder or Simulink Coder.
To achieve this workflow, you need:
  1. To use a predefined CMake-based toolchain. See more information in: Configure CMake Build Process- MATLAB & Simulink
  2. An RC file later called “version.rc” contains the metadata (We will explain later how to create it via a Post Code Generation Command).
Once these requirements are met you need to follow the steps below:

For MATLAB Coder:

In your MATLAB Code add the following line:
coder.updateBuildInfo('addSourceFiles', 'versioninfo.rc', '');
Then run the following commands:
 
cfg = coder.config('DLL'); %If you are generating an EXE this is not a necessary step cfg.Toolchain = myCMakeToolchain; %Change ‘myCMakeToolchain’ by the name of the toolchain you are planning to use codegen myTimesTwo -config cfg -args 1

For Embedded Coder:

  1. Use the “ert_shrlib.tlc” to generate a DLL. You can use the target of your choice to generate an EXE
  2. Add the “version.rc” source code to your Simulink model by running the command below or going to Model Settings/Code Generation/Custom Code/ Source Files. 
    set_param(gcs, ‘CustomSource’, ‘versioninfo.rc’)
  3. Set up the toolchain to a predefined CMake-based toolchain in Model Settings/Code Generation/Toolchain
  4. Build the DLL
You can also use the attached files to run a Post Code Generation command, which will automatically create an RC file containing the MATLAB version you are using (and other Metadata).
In that case, you don’t need the “version.rc” file, you will have to follow this workflow:
  1. Use the “ert_shrlib.tlc” to generate a DLL. You can use the target of your choice to generate an EXE
  2. Set up the toolchain to a predefined CMake-based toolchain in Model Settings/Code Generation/Toolchain
  3. Download the attached ZIP file and place the template RC and the “slVersionDLLMetadata.m” file in your current folder.
  4. Optional: You can modify the “slVersionDLLMetadata.m” file to set up a personal file description or other metadata.
  5. Run the following command 
    set_param(model,'PostCodeGenCommand','slVersionDLLMetadata(buildInfo)')
  6. Build your DLL/EXE
  7. You can see if the metadata has been added by right-clicking on your DLL/EXE with Windows Explorer and go to “Properties” and then “Details”

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!