I cannot use the Pre Build configuration to run scripts.

7 次查看(过去 30 天)
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.

采纳的回答

Adarsh
Adarsh 2025-6-4
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 个评论
Luca
Luca 2025-6-6
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Generated Code Compilation 的更多信息

标签

产品


版本

R2025a

Community Treasure Hunt

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

Start Hunting!

Translated by