I am using Matlab Coder to generate C code to be used as a subsystem of a larger C project. A first attempt at a code generation command would be
codegen -config cfg -o ...
where cfg
is the name of a coder.CodeConfig
object and ...
denotes that a list of functions and their argument specifications follows. The issue with this command is that it does not automatically generate the dependency tmwtypes.h
. I assume this is not an issue if one uses Matlab to compile the code, but I copy the generated files to the main project and build directly with gcc
, so I need that dependency to be included.
It turns out that the package
option can help. If I generate with
codegen -config cfg -package pkg -o ...
then a zip file pkg.zip
is generated, containing the generated code with the dependency tmwtypes.h
included. I can unzip this in the main project and compile; it works! Apparently the packNGo
function can be used to obtain similar results; in fact it seems likely that codegen
uses packNGo
to implement the package
option.
But this seems so silly! I shouldn't need to generate a zip file just to get the correct dependencies. There has to be a better way, right? So what is the proper way to generate the code and make sure that tmwtypes.h
is included? I suppose I could just copy it into the folder as part of my script, but the default location of tmwtypes.h
will be different on different machines, so that has its own set of issues. Matlab is clearly capable enough to detect and include the dependency, since it is included when using the package
option.
According to this it seems like I can get the platform dependent path to tmwtypes.h
by using the matlabroot
command:
matlabroot + "/extern/include/tmwtypes.h"
I can use this to copy tmwtypes.h
into the main project, as part of my script for code generation and compilation.
I would still appreciate information about a better solution, if there is one.