Main Content

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 this example model generates a Visual Studio Solution. These model configuration parameter settings control this code generation:

  • Set System target file to grt.tlc.

  • Set Template makefile to RTW.MSVCBuild.

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.

  • This example works with Microsoft Visual Studio, but not with Visual Studio Express.

  • 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

  1. Open the example model rtwdemo_counter_msvc. In the Command Window, type: open_system('rtwdemo_counter_msvc');.

  2. To generate debug output in the generated Visual Studio Solution, set the model configuration parameter Make command to make_rtw DEBUG_BUILD=1. (Omit this step if debug output is not required in the solution.)

  3. To generate code and build a program executable, initiate the build process.

  4. After the build process is complete, you can see a Visual Studio Solution was generated and placed in the msvc folder under folder rtwdemo_counter_msvc_grt_rtw.

  5. 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.

Related Topics