# Where’s the Code?

Today’s post is courtesy of my first guest blogger Tom Erkkinen, my colleague from the MathWorks office in Novi, Michigan!

Ever try to compile code generated by Real-Time Workshop on a computer without MATLAB installed and have it build the first time? If yes, great for you!

Now for the rest of us mere mortals, I’d like to introduce packNGo, a handy utility for porting generated code to new platforms.

Introduction

packNGo collects the generated code, locates all files needed to build the code, and packs it into a single zip file. It even includes those hard to find dependency files deep within your MATLAB installation directory. You can then go to a different computer, unzip, and build. Presto! No more link errors from missing headers.

Usage

packNGo is based on the BuildInfo API, which offers a programmatic way to interrogate and control the code generation, compilation, and build processes. You invoke packNGo by establishing a post processing code generation step, or hook point, using the set_param command. Once established, a zip file is generated during the code generation process in a flat or hierarchical structure.

I prefer the hierarchy because it clearly separates the code generated in my build directory (sDirFiles.zip) from the files in my MATLAB installation directory (mlrFiles.zip).

Example

The following commands generate and package code for a demo provided with Real-Time Workshop Embedded Coder, rtwdemo_cppencap. Note that this demo highlights C++ class generation in Release R2008b.

>> rtwdemo_cppencap; >> set_param(bdroot,'PostCodeGenCommand',...      'packNGo(buildInfo, {''packType'' ''hierarchical''})'); >> rtwbuild(bdroot);

The zip file produced is shown below.

Now you can go to your Hardware-in-the-Loop lab, system simulator, or real-time prototyping platform and build.

Caveats

packNGo operates on source files, such as *.c, *.cpp, *.h files but not other files such as compiler and link directives, or makefiles. Unnecessary files may be included but each release has fewer and fewer of these. Source code for S-functions is included in the zip package.