codegen with custom makefile

6 views (last 30 days)
Rian Koja
Rian Koja on 25 Jan 2019
Commented: Rian Koja on 30 Jan 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 Comment
Rian Koja
Rian Koja on 25 Jan 2019
By the way, I"ve noted that the generated rtwtypes.h contains:
include "tmwtypes.h"
Which wasn't generated.

Sign in to comment.

Accepted Answer

Denis Gurchenkov
Denis Gurchenkov on 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 Comments
Ryan Livingston
Ryan Livingston on 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 on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Build Configuration in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!