Conflict of the C++ codes generated by MATLAB Coder

18 views (last 30 days)
Peyman Ghasemi
Peyman Ghasemi on 20 Nov 2017
Edited: Mats on 12 Jan 2022 at 13:41
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.
  1 Comment
Christian Wissing
Christian Wissing on 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.

Sign in to comment.

Answers (1)

Denis Gurchenkov
Denis Gurchenkov on 22 Feb 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.
  1 Comment
Mats on 12 Jan 2022 at 13:39
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.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by