Effacer les filtres
Effacer les filtres

codegen with custom makefile

5 vues (au cours des 30 derniers jours)
Rian Koja
Rian Koja le 25 Jan 2019
Commenté : Rian Koja le 30 Jan 2019
I'm trying to generate C code for a simple function:
function[] = myfunc()
fprintf('Executing myfun\n');
fid = fopen('file_created_by_myfun.txt','w');
fwrite(fid,'This is written by myfun upon execution');
However, in the generated code a variable type boolean_T is used but not declared anywhere. It seems to me that no header with its declaration was included.
The script to generate the code is:
config_obj = coder.config('exe');
config_obj.GenCodeOnly = 'on';
codegen -config config_obj myfun
I can ask for single file and add custom code with:
config_obj = coder.FilePArtitioningMethod('SingleFile');
config_obj.CustomSourceCode = ['typedef unsigned int boolean_T;',newline,'#define true 1U',newline,'#define false 0U'];
This will allow me to compile the code properly, but it's a crappy solution, since I don't want to generate a single file, and the added source is not included in every file as needed.
Is there any way I can avoid having the boolean_T type being used? Or there some directive I should have used but I'm missing?
  1 commentaire
Rian Koja
Rian Koja le 25 Jan 2019
By the way, I"ve noted that the generated rtwtypes.h contains:
include "tmwtypes.h"
Which wasn't generated.

Connectez-vous pour commenter.

Réponse acceptée

Denis Gurchenkov
Denis Gurchenkov le 28 Jan 2019
Definition of boolean_T is contained inside tmwtypes.h. that file is located in matlabroot/extern/include, where "matlabroot" is the folder where MATLAB is installed. That file contains many other typedefs, it just happened that in your case, only boolean_T is required, but if your source MATLAB code was bigger / more complicated, other defines from tmwtypes.h would be used.
Simply put, the generated C code is not self-sufficient, it needs some .h files that are shipped with MATLAB. To get all the needed .h files and everything else into one place, you can use PackNGo feature, either on the command line:
or as the last step in MATLAB Coder ui (run "coder" command in MATLAB console and follow the prompts).
  2 commentaires
Ryan Livingston
Ryan Livingston le 30 Jan 2019
The generated code has basic typedefs in the file rtwtypes.h. As Denis says, this file includes tmwtypes.h when your target hardware is MATLAB Host Computer (the default). This ensures compatibility with shipped MathWorks libraries. If you set the hardware to something else you'll see that rtwtypes.h contains typedefs specific to your requested hardware and is self-sufficient. For example:
cfg.HardwareImplementation.ProdHWDeviceType = 'Intel->x86-64 (Windows64)';
codegen -config cfg ...
Rian Koja
Rian Koja le 30 Jan 2019
I've tryied simply copying tmwtypes.h from its location and it worked. I'm still checking how I'll work things for the long run, but PackNGo seem quite promising.

Connectez-vous pour commenter.

Plus de réponses (0)


En savoir plus sur Build Configuration dans Help Center et File Exchange


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by