Compile and Debug Generated C Code with Microsoft Visual Studio
This example shows how to generate code from a model and produce a Visual Studio® Solution. For the base example, see rtwdemo_counter
.
About This Example
Building the example model generates a Visual Studio Solution. These model configuration parameters control the code generation:
System target file
Toolchain
When you build the model with this configuration, Simulink® Coder™ generates code in a Visual Studio Solution. Add this solution to a Visual Studio C/C++ project to integrate generated code with your custom Visual Studio code.
Before You Start
This example builds code for Microsoft® Visual Studio running on Microsoft Windows® platforms.
Simulink Coder uses the GRT code format, which is intended for rapid prototyping.
Embedded Coder® uses the ERT code format, which is intended for production deployment.
Example Steps
Open the example model
rtwdemo_counter_msvc
. In the Command Window, type: open_system('rtwdemo_counter_msvc');Set System target file to
grt.tlc
(Generic Real-Time Target
).Set Toolchain to a value of the form
Microsoft Visual Studio Project <
year
> | CMake (64-bit Windows)
that specifies an installed version of Microsoft Visual Studio. For example,Microsoft Visual Studio Project 2019 | CMake (64-bit Windows)
.From the Apps gallery, open the Simulink Coder app.
To generate code and build a program executable, on the C Code tab, click Build.
When the build process is complete, in the
rtwdemo_counter_msvc_grt_rtw > build
folder, you see a generated Visual Studio Solution.In Microsoft Visual Studio, open the
rtwdemo_counter_msvc.sln
solution file.
Use the solution to build and debug the generated code in Visual Studio.