This project targets MATLAB Coder and Simulink Coder to emit C++ source. Generated binaries are not tracked — only the sources the build produces belong in version control.
See
codegen/for the stub configuration that ships with this template.
- Mark the function you want to compile as the entry point:
>> coder -config cfg foo_entry
- Use
codegen/matlab/codercfg.m.exampleas a starting point for acoder.config('dll','ecoder',true)orcoder.config('lib'). - Generated
.cpp/.hppgo intocodegen/matlab/src/. - Always run
runtests('tests')on the generated code separately from the M-code.
For more than one entry point, list them in
codegen/matlab/entries.txt and let the driver do the iteration:
# Linux / macOS / WSL / Git Bash
./scripts/build_codegen.sh
# Native Windows PowerShell
.\scripts\build_codegen.ps1- Open the model,
Ctrl+B, thenModel Configuration Parameters->Code Generation-> set System target file toert.tlcand Language toC++. - Save a copy of the configuration as
codegen/simulink/<model>_config.mso it can be reapplied viaload('my_model_config.mat')orsetActiveConfigSet. - Generate code into
codegen/simulink/<model>/. Commit only the.cpp/.hpp, the*.ert_main.cpp(if hand-written), and any hand-written CMake / build files.
For more than one model, list them in
codegen/simulink/entries.txt (one model name per line) and run the
same driver:
# Linux / macOS / WSL / Git Bash
./scripts/build_codegen.sh
# Native Windows PowerShell
.\scripts\build_codegen.ps1The driver exits non-zero if any entry fails, so the same script works for local development and a future CI step without changes.
*.o,*.obj,*.so,*.dylib,*.dll,*.exeslprj/,slexec/,slbuild/,build/,cmake-build-*/*.slxc,*.slx.r20*
These are covered by the root .gitignore.
Before pushing generated code, confirm:
-
codegen/**/{*.cpp,*.hpp}is staged. - No object files or build dirs are staged
(
git status --ignoredis your friend). - The generated sources compile cleanly with the project's chosen C++ toolchain.