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.
-package/packNGo(they are the same thing under the hood) is unnecessary? If you already are using a script to copy the requisite header files into your main project, could you not just as easily have your script extract all the generated code and dependencies from the packaged zip file?-packageis the recommended workflow because it will gather all of the dependencies. So if you update your project in such a way that the generated code depends on a new header file,-packagewill pull it in automatically.