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

4 ビュー (過去 30 日間)

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?

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 9 月 27 日
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”

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by