Can I change the name of a function during codegen?

Can I change the name of a function during codegen? For example, if I hava a Matlab function called foo, can I make its genrated C function name be something like foo_cg (_cg for CodeGen)?. The motivation for this is that I have a custom version of the C foo and legacy code that uses it, and I don't want to change that code. I also have legacy Matlab code that uses the Matlab foo, so I don't want to changes its name either.

 채택된 답변

Denis Gurchenkov
Denis Gurchenkov 2020년 3월 5일

0 개 추천

Unfortunately, no, there is no mechanism to rename the function in the generated C code. I've added a request for the development team to add this capability in a future release.
If you use MATLAB Coder to generate C++ code, then there is a possible solution -- use the "Generate code in a namespace" feature, so that you get C++ code for foo() in a custom namespace of your choice, so it does not collide with your other foo: https://www.mathworks.com/help/coder/ug/cpp-code-generation.html

댓글 수: 3

Tyson Lawrence
Tyson Lawrence 2020년 3월 5일
편집: Tyson Lawrence 2020년 3월 5일
I was thinking about C++ namespaces, but hadn't looked to see if they were supported. This could be a nice solution for me. Currently, I am using a script to change the names post code generation. This works for now, but I'm not sure how well it will scale. I might migrate to C++ and try namespaces.
Could you just add a #define ? In most compilers these days, that does not even require a file: it can often be done by adding a -DNAME=VALUE option to the command line or build options.
Has this problem been solved by now so that function names of standard functions such as round() can be changed to e.g. round_cg() in the generated c-code?

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

추가 답변 (1개)

Jeff Tackett
Jeff Tackett 2025년 3월 4일

1 개 추천

Starting in R21a, you can configure generated code naming via: CustomFileNameStr
In the MATLAB Coder GUI, it looks like:

제품

릴리스

R2019a

태그

Community Treasure Hunt

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

Start Hunting!

Translated by