codegen with custom makefile

3 visualizaciones (últimos 30 días)
Rian Koja
Rian Koja el 25 de En. de 2019
Comentada: Rian Koja el 30 de En. de 2019
I'm trying to generate C code for a simple function:
function[] = myfunc()
%#codegen
fprintf('Executing myfun\n');
fid = fopen('file_created_by_myfun.txt','w');
fwrite(fid,'This is written by myfun upon execution');
fclose(fid);
end
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 comentario
Rian Koja
Rian Koja el 25 de En. de 2019
By the way, I"ve noted that the generated rtwtypes.h contains:
include "tmwtypes.h"
Which wasn't generated.

Iniciar sesión para comentar.

Respuesta aceptada

Denis Gurchenkov
Denis Gurchenkov el 28 de En. de 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 comentarios
Ryan Livingston
Ryan Livingston el 30 de En. de 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 el 30 de En. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Build Configuration en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by