I cannot use the Pre Build configuration to run scripts.

7 views (last 30 days)
Hello everyone.
I have Matlab 2025a with the Embedded Coder toolbox installed and the MinGW toolchain set up. My problem is that in the Model Settings > Code Generation > Custom Code section I can't find the Pre or Post Building option to trigger scripts. Another method that didn't work is in the startup file, where in Post Build I can use: set_param(model, 'PostCodeGenCommand', myScript); but the set_param(model, 'PreCodeGenCommand', myScript); does not work. Do you have any other suggestions? My goal is to press the Build button and run the Pre Build script -> Build -> and so on.......
Thank you in advance.

Accepted Answer

Adarsh
Adarsh on 4 Jun 2025
Hi @Luca,
I understand that you are searching for an option to run two scripts, one before the start of build process and other after completion of build process.
In MATLAB you can set the “Post Code Generation Command” to run any script after code generation but no method exists for “Pre Code Generation”.
To access the “Post Code Generation Command” option click on “Model Settings” and then select “Code Generation” and select “Advanced Parameters” to find the “Post Code Generation Command”.
You can also do this programmatically by following the process in the documentation link below:
Alternatively, you can create a custom script in which, “Pre Build” command is executed and then “slbuild” is executed for model build process and then “Post Build” command is executed as shown in the example below:
disp('Running pre-build tasks...');
myPreBuildScript;
disp('Building model...');
slbuild('myModel');
disp('Running post-build tasks...');
myPostBuildScript;
For more customization, a custom build hook file can be used as shown in the documentation link below:
For more information, the following documentation links can be referred:
I hope this helps.
  1 Comment
Luca
Luca on 6 Jun 2025
Understood, I will follow your advice using the script you suggested; at the moment, I don't see any other alternatives. Thank you. Best regards.

Sign in to comment.

More Answers (0)

Categories

Find more on Generated Code Compilation in Help Center and File Exchange

Tags

Products


Release

R2025a

Community Treasure Hunt

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

Start Hunting!