Skip to content

Creating a program

Peter Corke edited this page Sep 4, 2018 · 1 revision

A typical STL program comprises a file user.m which contains the "main" thread of execution which is executed when the binary is launched.

Building an executable

The codegen build is defined by a supplied MATLAB script make.m. You need to edit this file to suit your build. The bulk of this file is concerned with setting up the codegen and build parameters. The last line describes the files that comprise your application and should be changed to suit.

codegen user.m thread1.m -args int32(0) thread2.m  -config cfg

The first file listed should be user.m which has the "main" code for your application. It is called at run time.

After this you should list any other files that contain thread definitions. Each of these looks like a regular MATLAB function definition file where function.m defines a MATLAB function function that has no return values and has at most one argument.

If the thread has no arguments, just list its name on the codegen line, like thread2.m in the example above.

If the thread has an argument, list its name on the codegen line, like thread1.m in the example above. It must be followed by -args to inform codegen what kind of argument it expects. At the moment only int32 is supported.

Now run the make script make.m

>> make

and if there were no compilation or link errors, there will be an executable file user in the current directory which we can run

% ./user

Intermediate C and object files will be generated in the local folder codegen/exe/user.

Trouble shooting

  1. Threads will often be infinite loops and codegen will complain about them, ignore the warning
Warning: Function 'thread3' does not terminate due to an infinite loop.
  1. If there are errors regarding main.c, stl.c or stl.h ensure that the folder stl is in your MATLAB path.

  2. Any other errors will yield a report like

Error in ==> user Line: 7 Column: 38
Code generation failed: View Error Report

Click on the hyperlink to open the report, the BuildLog tab is the most useful part, and fix your error(s).

Notes on coding

There's no need to put a semicolon on the end of each line. The generated code won't print the result of the line.