필터 지우기
필터 지우기

Conflict of the C++ codes generated by MATLAB Coder

조회 수: 6 (최근 30일)
Peyman Ghasemi
Peyman Ghasemi 2017년 11월 20일
댓글: Stian Kristoffer Endresen 2022년 3월 31일
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
Christian Wissing
Christian Wissing 2017년 11월 30일
편집: Christian Wissing 2017년 11월 30일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Denis Gurchenkov
Denis Gurchenkov 2018년 2월 22일
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
Mats
Mats 2022년 1월 12일
편집: Mats 2022년 1월 12일
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
Stian Kristoffer Endresen 2022년 3월 31일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by