Multiple definitions of the same function in generated code

I have a model where the interfaces are configured as GetSet. Corresponding header file is also added in port configuration. When code is generated, definition for these Get/Set functions are generated in <model>.c file. But there is also a headerfile, with same name as what is configured in the ports generated in instrumented folder inside ert_rtw. This causes multiple definition error when trying to run SIL. How do i avoid the extra header file from being generated. It is already present in my working directory and is added to custome code sttings in model config.

답변 (1개)

sneha
sneha 2025년 11월 10일

0 개 추천

To avoid having Embedded Coder generate that extra header or duplicate files, you must adjust the storage class / code-generation settings so that the code generator assumes your external file covers the definitions and does not generate its own.
To fix it:
  1. Set Data Scope to Imported for all signals using Get/Set.
  2. This tells Embedded Coder to use your existing code instead of generating new ones.
  3. In Model Settings → Code Generation → Custom Code, add your header (MyInterface.h) and source (MyInterface.c).
  4. Make sure the build doesn’t include the auto-generated header from model_ert_rtw/instrumented/.
  5. Rebuild and check the code generation report — only your header should appear.
Supporting MathWorks Docs:
https://www.mathworks.com/help/rtw/ug/choose-a-built-in-storage-class-for-controlling-data-representation-in-the-generated-code.html– use this to understand how to control how signals and parameters appear in generated code.
https://www.mathworks.com/help/ecoder/ug/design-custom-storage-classes-and-memory-sections.html– refer here to learn how to define and configure your own storage classes (e.g., Imported, Get/Set).
https://www.mathworks.com/help/ecoder/ug/getset-custom-storage-classes.html– check this for details on using Get/Set to access data through custom getter/setter functions and link external code.

댓글 수: 1

sandip mule
sandip mule 대략 21시간 전
편집: sandip mule 대략 21시간 전
Hello, Have you tried SIL for input and output signal using getset storage class ? I am working on this and I am facing multiple defination error in xil_interface.c and GetSet.c file GetSet.c contain defination of external input and output getter setter function GetSet.h contains declarations for the same So to resolve this I have used conditional compilation technique and conditionally disabled compilation of getter setter function in GetSet.c file After that I am facing another error which is undefined reference error and I am stuck there.

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

카테고리

도움말 센터File Exchange에서 Deployment, Integration, and Supported Hardware에 대해 자세히 알아보기

제품

릴리스

R2024b

질문:

2025년 11월 7일

편집:

대략 21시간 전

Community Treasure Hunt

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

Start Hunting!

Translated by