# Where’s the Code?7

Posted by Seth Popinchalk,

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.

I hope you enjoyed my quick introduction to this handy but not well known feature.   Please read our documentation or leave a comment for more about packNGo.

Chitlesh GOORAH replied on : 1 of 7

Hello Seth, Thanks for the tip. I am curious whether with the packNGo function the zip file is platform independent. In other words will the files under the zip file be compiled under Linux or Mac ?

As I can see the mlrFiles.zip contains matlab dependency files. Could you please give us some details about the licensing conflicts that a company will have if the rtwdemo_cppencap.zip file is to be sold to another company?

tom erkkinen replied on : 2 of 7

The zip file is just a standard zip, so you can unpack it from MATLAB or any zip utility on any platform.

Guy Rouleau replied on : 3 of 7

@ Chitlesh, The files are not all platform independent. The C-code is, but the auto-generated makefile is based on the TMF-file selected during the build process. If you want to generate code on a windows platform and use it on a UNIX platform, you have to modify the “grt_unix.tmf” template make file for your machine. Guidelines to compile generated code on a computer without MATLAB for releases before the existence of “packNGo” can be found at this address:

http://www.mathworks.com/support/solutions/data/1-19EH0.html

The modifications to the template makefile described in this page are valid for the current release.

Boris replied on : 4 of 7

hi Seth,hope you could help me,
i am having problems with the C code generated on real time workshop, (R2009b,VS 2005),
after adding the .c .h files (subsystem name CORN3) i tried to compile the project and had some problems, missing libraries:
vipdrawshapes_rt.h
lexicmp.h
dsp_rt.h
dsp_iso_math_rt.h
dspsizeof_rt.h
dspsvd_rt.h
vipprojective_rt.h
and then i had a problems without line numbers…:
error LNK2019 : unresolved external symbol_MWDSP_svd_R referenced in function CORN3_STEP file: CORN3.obj
error LNK2019 : unresolved external symbol_MWVIP_Are3PtsCollinear referenced in function CORN3_STEP CORN3.obj
error LNK2019 : unresolved external symbol_MWVIP_CalculateXforumMtrx_R referenced in function CORN3_STEP CORN3.obj
error LNK2019 : unresolved external symbol_MWVIP_FillBackGroundValues_R referenced in function CORN3_STEP CORN3.obj
error LNK2019 : unresolved external symbol_MWVIP_XforumonesubDevision_R referenced in function CORN3_STEP CORN3.obj

(i added the libraries: properties->c->additional include directories)

i think that the problems appear because the way i add the VIP library it is right? what should i do?
thank you for your time

Seth replied on : 5 of 7

@Boris – These errors seem to be related to your use ofthe Video and Image Processing blockset. I recommend you contact technical support for further assistance.

G Torralba replied on : 6 of 7

Hello,
good information.
My question is very simple: how can I disable the PostCodeGenCommand, case I want to generate the code without Pack and Go?
Once I set

>> set_param(‘mymodel’,'PostCodeGenCommand’,…
‘packNGo(buildInfo, {”packType” ”hierarchical”})’);

it is always executed.

Thank you in advance,
G. Torralba

Remi THOMAS replied on : 7 of 7

Hello Torralba,

I had the same problem.
I managed it by typing this in the Command Window :

>> set_param(‘mymodel’,’PostCodeGenCommand’,’0′);

It works !

Let me know if it gives you satisfaction.

Rémi THOMAS.

What is 9 + 10?

Preview: hide

These postings are the author's and don't necessarily represent the opinions of MathWorks.