{"id":38,"date":"2008-11-26T02:30:41","date_gmt":"2008-11-26T02:30:41","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/2008\/11\/26\/wheres-the-code\/"},"modified":"2017-04-27T08:45:58","modified_gmt":"2017-04-27T13:45:58","slug":"wheres-the-code","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2008\/11\/26\/wheres-the-code\/","title":{"rendered":"Where&#8217;s the Code?"},"content":{"rendered":"<p><strong>Today&#8217;s\r\npost is courtesy of my first guest blogger <a\r\nhref=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/7529\">Tom\r\nErkkinen<\/a>, my colleague from the <a href=\"https:\/\/www.mathworks.com\/company\/aboutus\/directions\/novi--united-states.html\">MathWorks office in Novi, Michigan<\/a>!<\/strong><\/p>\r\n\r\n\r\n\r\n<p>Ever try to\r\ncompile code generated by <a href=\"https:\/\/www.mathworks.com\/products\/rtw\/\">Real-Time\r\nWorkshop<\/a> on a computer without MATLAB installed and have it build the first\r\ntime? If yes, great for you! <\/p>\r\n\r\n\r\n\r\n<p>Now for the\r\n    rest of us mere mortals, I&#8217;d like to introduce <span\r\n        style='font-family:\"Courier New\"'><a\r\n        href=\"https:\/\/www.mathworks.com\/help\/releases\/R2008b\/toolbox\/rtw\/ref\/packngo.html\">packNGo<\/a><\/span>,\r\na handy utility for porting generated code to new platforms.<\/p>\r\n\r\n<p><strong>Introduction<\/strong><\/p>\r\n\r\n<p><span style='font-family:\"Courier New\"'>packNGo<\/span> collects the generated code,\r\nlocates all files needed to build the code, and packs it into a single zip\r\nfile. It even includes those hard to find dependency files deep within your\r\nMATLAB installation directory. You can then go to a different computer, unzip,\r\nand build. Presto! No more link errors from missing headers.<\/p>\r\n\r\n\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/packNgoModelToZipFiles.png\" alt=\"Generate code, \r\nand pack the source into a zip file, move the zip file to another system, \r\nunpack the code and build.\"><\/p>\r\n\r\n<p><strong>Usage<\/strong><\/p>\r\n\r\n<p><span style='font-family:\"Courier New\"'>packNGo<\/span> is based on the BuildInfo API,\r\nwhich offers a programmatic way to interrogate and control the code generation,\r\ncompilation, and build processes. You invoke <span style='font-family:\r\n\"Courier New\"'>packNGo<\/span>\r\nby establishing a post processing code generation step, or hook point, using\r\nthe <span style='font-family:\"Courier New\"'>set_param<\/span> command. Once established, a zip file\r\nis generated during the code generation process in a flat or hierarchical\r\nstructure. <\/p>\r\n\r\n\r\n\r\n<p>I prefer\r\nthe hierarchy because it clearly separates the code generated in my build\r\ndirectory (sDirFiles.zip) from the files in my MATLAB\r\ninstallation directory (mlrFiles.zip).<\/p>\r\n\r\n<p><strong>Example<\/strong><\/p>\r\n\r\n<p>The\r\nfollowing commands generate and package code for a demo provided with Real-Time\r\nWorkshop Embedded Coder, <span style='font-family:\"Courier New\"'>rtwdemo_cppencap<\/span>. Note that this demo highlights C++\r\nclass generation in Release R2008b.<\/p>\r\n\r\n<p><code style=\"font-size: 11pt;\">&gt;&gt; rtwdemo_cppencap;<br>\r\n        &gt;&gt; set_param(bdroot,'PostCodeGenCommand',...<br>\r\n        &nbsp;&nbsp;&nbsp;&nbsp;    'packNGo(buildInfo, {''packType'' ''hierarchical''})');<br>\r\n&gt;&gt; rtwbuild(bdroot);<\/code><\/p>\r\n\r\n<p>The zip\r\nfile produced is shown below. <\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2008Q4\/packNgoZipFiles.png\" alt=\"Zip files created by Real-Time Workshop packNgo\"><\/p>\r\n\r\n<p>Now you can\r\ngo to your Hardware-in-the-Loop lab, system simulator, or real-time prototyping\r\nplatform and build.<\/p>\r\n\r\n<p><strong>Caveats<\/strong><\/p>\r\n\r\n<p><span style='font-family:\"Courier New\"'>packNGo<\/span> operates on source files,\r\nsuch as <tt>*.c<\/tt>, <tt>*.cpp<\/tt>, <tt>*.h<\/tt> files but not other files such as\r\ncompiler and link directives, or makefiles. Unnecessary files may be included\r\nbut each release has fewer and fewer of these. Source code for S-functions is\r\nincluded in the zip package.<\/p>\r\n\r\n\r\n\r\n<p>I hope you\r\nenjoyed my quick introduction to this handy but not well known\r\nfeature.&nbsp;&nbsp; Please read our documentation or <a\r\nhref=\"https:\/\/blogs.mathworks.com\/seth\/?p=38&amp;#comment\">leave a comment<\/a>\r\nfor more about <a\r\nhref=\"https:\/\/www.mathworks.com\/help\/releases\/R2008b\/toolbox\/rtw\/ug\/bqufw6y.html#bqvil5f\">packNGo<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>Today&#8217;s\r\npost is courtesy of my first guest blogger Tom\r\nErkkinen, my colleague from the MathWorks office in Novi, Michigan!\r\n\r\n\r\n\r\nEver try to\r\ncompile code generated by Real-Time\r\nWorkshop on... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2008\/11\/26\/wheres-the-code\/\">read more >><\/a><\/p>","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,65,55],"tags":[454,22,441],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/38"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=38"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/38\/revisions"}],"predecessor-version":[{"id":6508,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/38\/revisions\/6508"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=38"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=38"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=38"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}