How to integrate codegen generated multiple different C projects using calls to generated functions?

7 visualizzazioni (ultimi 30 giorni)
As far as I know through internet searching, in order to fuse multiple code/functions generated by codegen in one big project, you can either integrate different C++ code projects into one bigger project or codegen commands specify multiple entry signature functions at the same time.
But the problem I am having is how to integrate multiple different C projects into one big project? There are a lot of functions with the same name, for example, <myProject1_emxutils.h>,<myProject2_emxutils.h> files have the function with the same name that defines `emxInit_int32_T(emxArray_int32_T **pEmxArray)`, in this big C project when I call main entry function function myProject1() there are problems, like memory problems at the moment of running, "free(): invalid next size (fast)", how to solve it? Or a workaround?

Risposta accettata

Denis Gurchenkov
Denis Gurchenkov il 18 Set 2023
Modificato: Denis Gurchenkov il 19 Set 2023
Hi cui,
The memory issues you describe can happen if both projects contain some unnamed structu types (that is, types that do not posses unique name attached to them using coder.cstructname) - in that case, the emx* functions could be named identically but contian different data, and a memory corruption would occur if you just merge the projects together.
One known workaround is to add unique prefixes to the name of functions generated in each project (this requires the Embedded Coder product license):
cfg = coder.config(‘lib’);
cfg.CustomSymbolStrEMXArrayFcn = ‘proj1_emx$M$N’;
... now generate code using this config, e.g. codegen.... -config cfg....
Another workaround is to generate C++ code and use seprate namespaces.
  2 Commenti
cui,xingxing
cui,xingxing il 19 Set 2023
@Denis Gurchenkov Thank you for your attention, the above is a common problem for me. In addition to the 2 ways I have given so far, I thought about whether it is possible to do this below?
Since every time a project generates C/C++ code it generates some header files or implementation files with the same name in common, and their role is either to initialise arrays, which starts with emx_* for C, or coder::array for C++, or array boundary out-of-bounds detection, or common datatype definitions, etc., which are common to all projects. So maybe encapsulate their common base C/C++ functionality into separate modules, and download this base library code uniformly when you need C/C++ generated for each individual project, I wonder if this is feasible? Just my personal opinion.
In addition, what you said about using unique prefix names to distinguish project files, although theoretically feasible to ensure the integrity and independence of each project, but it will bring about an increase in the amount of code (number of files) for the same "functionality".
Denis Gurchenkov
Denis Gurchenkov il 19 Set 2023
Modificato: Denis Gurchenkov il 19 Set 2023
I was wrong when I said there is no workaround. Cui, can you please try the following, and see if it helps?
cfg = coder.config(‘lib’);
cfg.CustomSymbolStrEMXArrayFcn = ‘proj1_emx$M$N’;
now generate code with this config. You should see generated code has unnique prefixes for all emx functions Now, for the next project, change the prefix. This config parameter requires Embedded Coder license.
I understand this is not the perfect solution. But, does this work for your use case?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB Coder in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by