Add an icon (.ico) to standalone (.exe) app created with Simulink Coder
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Overview:
Using Matlab/Simulink R2024a.
I currently make a standalone (.exe) app with a build script that calls slbuild on a Simulink model and then uses a custom ert_main.c and a custom ert_make_rtw_hook.m with the build process to compile the C-code and make a standalone executable that runs in a terminal window. When the exe runs, the title icon bar in the window and in Windows task bar is just a generic Windows program icon. How can I update my build process to add a custom icon (.ico) image to the icon bar of the deployed app window?
What I Have Tried:
I Google'd the answer, used ChatGPT, and the Matlab AI Playground for this and think I got kind of close but ran into an error. I came up with the following:
- Added desired .ico file to my Simulink Project path
- Created a .rc file to specify the icon. Example: app_icon.rc:
IDI_ICON1 ICON "app_icon.ico"
- Placed the .rc and .ico files in the working directory
- Ran the system command to make a .res file:
system('windres app_icon.rc -o app_icon.res')
- Defined a Matlab function for custom build arguments as follows:
function setBuildArgsIcon(buildInfo)
% Specify the resource file to include the icon
rcFile = which('app_icon.res');
% Ensure the RC file exists
if exist(rcFile, 'file') ~= 2
error('Resource file app_icon.rc not found.');
end
% Add the resource file to the build
buildInfo.addSourceFiles(rcFile);
- Then in the 'before_make' section of my ert_make_rtw_hooks.m, I call the function:
case 'before_make'
% Called after code generation is complete, and just prior to kicking
% off make process (assuming code generation only is not selected.) All
% arguments are valid at this stage.
% Add an icon to the deployed app
setBuildArgsIcon(buildInfo)
- Run my build script and encounter the following error:
Error using coder.make.internal.checkSourceExtensions (line 35)
In the build information, the source files (app_icon.res) have extensions that are not registered with the toolchain (MinGW64 | gmake (64-bit Windows)). The registered file extensions are
.CPP, .c, .c++, .cc, .cp, .cpp, .cxx. Register the source file extensions by updating the toolchain definition or change the source file names.
Error in coder.make.internal.genMakefileAndBuild (line 89)
coder.make.internal.checkSourceExtensions(buildInfo, runMakefile, ...
Error in coder.make.internal.StandardCodeBuildStrategy/build (line 18)
buildResults = coder.make.internal.genMakefileAndBuild...
Error in codebuild (line 247)
lMakeResult = localStrategy.build(buildInfo, ...
Error in coder.internal.ModelBuilder>i_buildProcedure (line 1725)
compileResult = codebuild(lBuildInfoUpdated, compileBuildOptsUpdated);
Error in coder.internal.ModelBuilder.make_rtw (line 135)
[modelBuildResult, mainObjFolder] = i_buildProcedure...
Error in build_target
Error in build_target
Error in build_standalone_rtw_target
Error in slbuild_private
Error in slbuild_private
Error in sl_feval
Error in coder.internal.codegenAndCompile
Error in slbuild
Error in slbuild
Error in buildModel (line 20)
slbuild(modelName);
This is where I got stuck. How do I update my toolchain to recognize .ico, .rs, and .res files? ChatGPT suggested the file should be an internal file called "toolchaininfo.xml" but I'm not able to find this file on my machine and even if I found it, I'm not sure what to do with it.
0 comentarios
Respuestas (1)
Kanishk
el 4 de Feb. de 2025
Editada: Kanishk
el 10 de Feb. de 2025
I understand that you want to add an icon to the standalone executable generated for the Simulink model. The icon file is added linked to executable during the make process. As icons are resource content, they can not be usually modified after generating the executable. To access the make file which builds the executable, you can first generate code only using 'GenerateCodeOnly' flag and modify the 'model.mk' file to link the icon file during compiling. To generate the '.res' file for icon add the 'coff' flag in the 'windres' command to save the '.res' file in usable format.
windres app_icon.rc -o coff app_icon.res
In the '<model_name>.mk' file, link the '.res' file with '<model_name>.c' during compiling.
A simpler method is using a third-party tool to modify the resources of an executable such as 'ResourceHacker'. You can download the zip file and add the 'ResourceHacker.exe' in the path. You can then directly use the '.ico' file to link the icon to the generated executable.
resourcehacker.exe -open CounterModel.exe -save CounterModel.exe -action addskip -res myicon.ico -mask ICONGROUP,MAINICON
You can use the 'system' command in MATLAB to run terminal commands and create a MATLAB script which builds the model using 'slbuild' and uses the 'system' command to change the icon.
Here are the links to some useful documentations:
0 comentarios
Ver también
Categorías
Más información sobre Test Model Components en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!