Conflict of the C++ codes generated by MATLAB Coder
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all;
I have generated two c++ codes from my MATLAB functions (Suppose them func1 and func2). I can run each of them correctly in Visual Studio 2015; but when I want to use both of them in my c++ project, they have conflicts and cause some errors. The errors are because of similar names of the .cpp and .h files and the internal functions of each generated function. for example both func1 and func2 has "rt_nonfinite.cpp" file and also the internal functions and structures of the "func1_types.h" and "func2_types.h" are same and cause the error related to multiple definition of the functions and structures with same name.
Because I should use multiple MATLAB Coder generated functions in my project, it is not possible to change each common function one by one. Does anybody has idea to solve this problem.
Sincerely;
Peyman
1 commentaire
Christian Wissing
le 30 Nov 2017
Modifié(e) : Christian Wissing
le 30 Nov 2017
Actually, I have the same problem with two independent C-Code coder projects generating functions with equal names, which leads to linker errors for already defined symbols.
I guess defining some kind of function prefix for each generated function, which is unique for each project, would fix the issues. But I haven't found a way to achieve this with the coder.
Réponses (1)
Denis Gurchenkov
le 22 Fév 2018
There is a way to define a per-project prefix for each function/global vairable/typedef that coder generates. But you have to have Embedded Coder license to get that feature. If you have one, then in the settings (more settings / code appearance / identifier format) you can add a custom prefix to all of the identifier types.
The other problem that you mentioned (file named rt_nonfinite.cpp that is in both projects) has no proper solution. But the file seems to be identical in between the projects, so I think you can just overwrite it when copying files from the 2nd project to the common folder.
2 commentaires
Mats
le 12 Jan 2022
Modifié(e) : Mats
le 12 Jan 2022
I have the same problem with two different rt_nonfinite.h files from two separate C code generations, which are to be used in the same project.
The first rt_nonfinite.h file, generated by matlab coder, contains
extern void rt_InitInfAndNaN();
and the other rt_nonfinite.h file, generated by simulink coder, contains the line
extern void rt_InitInfAndNaN(size_t realSize);
This confuses the complier.
Any workaround would be nice. I have 2019b, with matlab, simulink, and embedded coder.
Stian Kristoffer Endresen
le 31 Mar 2022
It is possible to add a prefix without purchasing the embedded coder license, but it is a little tedious. First, compile your project with both the exported C/C++ codes included. Take a look at the error messages, and note the name and location of all functions that cause "multiple definition of" errors. Then remove one of the exported C/C++ codes from your project, which would allow you to compile again without errors. Now you should be able to go through the exported C/C++ code still in your project and Refractor->Rename all the functions that caused errors, adding a prefix/postfix.
When finished, add the second exported C/C++ code back in the project. This is not the most elegant solution, but it does work.
Voir également
Catégories
En savoir plus sur MATLAB Coder dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!