MATLAB Answers

Conflict of the C++ codes generated by MATLAB Coder

18 views (last 30 days)
Peyman Ghasemi
Peyman Ghasemi on 20 Nov 2017
Answered: Denis Gurchenkov on 22 Feb 2018
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.


Sign in to comment.

Sign in to answer this question.