Modular Code Generation Conflicts with Autogenerated Files
Ältere Kommentare anzeigen
Dear Matlab Community,
In my work. I have large code genation projects that I would like to break apart and build in pieces.
Trying to follow the steps listed here:
- The idea being that you can create a code geneneration application (lets call if function_A).
- Generate code for function_A and call it in a larger code generation application function_B.
- Where function_A's generated code is called in function_B.
To do this. I call function_A in function_B using a wrapper with "coder.ceval"
- I update build paths to function_A code gen source code (coder.updateBuildInfo('addIncludePaths',path);)
- I add source files for each source file created by function_A (coder.updateBuildInfo('addSourceFiles','{file_name}.c',path);)
- I add includes for each file created by function_A (coder.cinclude('{file_name}.h');)
I have trouble when including existing generated code into projects within the Matlab Coder App.
Specific Issue: function_A creates a files called ''rt_nonfinite.c' and 'rt_nonfinite.h', and function_B tries to also create these.
Warning: File
'{path}'
not found.
> In emcRemoveFile
In emcBuildClean
In emcBuildClean
In emlckernel
In emlckernel
In emlckernel
In emlckernel
In emlcprivate
In coder.internal.gui.codegenWrapper
In codeUnifiedProject
In codeUnifiedProject
In emlcprivate
ninja: error: build.ninja:46: multiple rules generate build/win64/rt_nonfinite.obj [-w dupbuild=err]
??? Build error: C compiler produced errors. See the Build Log for further details.
So I think this makes sense. But how do I handle this?
I know I cannot remove the includes to the rt_nonfinite.c and header files from the wrapper for function_A because when I do the build fails for that component.
I tried including the function_A path, source file, and header file in the "Custom C Code for Generated Files" section of the Coder App but this didnt seem to help.
I hoped that it would stop function_B from creating rt_nonfinite.c and .h.
Because function_B hasnt been made yet, I cannot include it in the function_A build... hmm.
I am using Matlab 2020a and am unsure how to proceed.
Any info would be appreciated. Thanks.
Antworten (1)
Rashed Mohammed
am 2 Nov. 2020
Hi Brian,
The following is a sample example on how to include generated code and modularize large projects.
Folder Structure:
D/
- add.m
- add3.m
- add4.m
- codegen/lib/
- add/
- add3/
- add4/
Code:
add.m
function z = add(x,y)
z = x+y;
end
add3.m
function w = add3(x,y,z)
w = 0;
if coder.target('MATLAB')
w = x+y+z;
else
path = 'D:/codegen/lib/add';
coder.updateBuildInfo('addIncludePaths',path);
coder.updateBuildInfo('addSourceFiles','add.c',path);
coder.cinclude('add.h');
temp = 0;
temp = coder.ceval('add',x,y);
w = coder.ceval('add',temp,z);
end
end
add4.m
function out = add4(x,y,z,w)
out = 0;
if coder.target('MATLAB')
out = x+y+z+w;
else
path1 = 'D:/codegen/lib/add';
path2 = 'D:/codegen/lib/add3';
coder.updateBuildInfo('addIncludePaths',path1);
coder.updateBuildInfo('addIncludePaths',path2);
coder.updateBuildInfo('addSourceFiles','add.c',path1);
coder.updateBuildInfo('addSourceFiles','add3.c',path2);
coder.cinclude('add.h');
coder.cinclude('add3.h');
temp = 0;
temp = coder.ceval('add3',x,y,z);
out = coder.ceval('add',temp,w);
end
end
Hope this helps !
2 Kommentare
Brian Stevens
am 2 Nov. 2020
Jean-Pierre Theron
am 29 Sep. 2022
Hi Brain
Did Mathworks provide you with a solution to this problem? I am experiencing a similar problem with the nonfinite number support files while trying to combine autocoded MATLAB code with an autocoded Simulink model.
Kategorien
Mehr zu Simulink Coder finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!