Getting error main.c:405: undefined reference to 'rt_InitInfAndNaN' for .mdl model in MATLAB R2024a and above versions

19 visualizaciones (últimos 30 días)
In MATLAB R2024a/b, I get the error main.c:405: undefined reference to 'rt_InitInfAndNaN' when building code from a .mdl Simulink model even when Support non-finite numbers (NaN or Inf)" option is enabled.
This issue does not occur in older versions such as R2023a/b or when using the same model saved as a .slx file
why and how to resolve this ?

Respuestas (1)

Hitesh
Hitesh el 10 de Jun. de 2025
Editada: Hitesh el 10 de Jun. de 2025
Hi Usha,
The rt_InitInfAndNaN function is a support routine inserted automatically when your model may involve special floating-point values, such as:NaN (Not a Number)Inf (Infinity). Its purpose is to initialize platform-specific representations of these values so they can be used reliably in the generated code.If you want to remove this function, you must ensure your model does not require non-finite values.You can do this by changing the following code generation settings:
  • Go to Model Configuration Parameters Under Code Generation > System target file:Ensure it is set to 'ert.tlc'.
  • Go to Code Generation > Interface tab:Set "Support non-finite numbers" to OFFSet "MAT-file logging" to OFF if not neededDisabling support for non-finite numbers tells Embedded Coder that your application will not use NaN, Inf, or -Inf, allowing it to omit rt_InitInfAndNaN from the generated code.
If this issue still persist, you need to follow the following troubleshooting steps that help you to know more about it.
Convert .mdl to .slx: This is the simplest and most effective solution.
  • Open the .mdl model in R2024a.
  • Save it as an .slx:
save_system('modelname', 'modelname_converted.slx')
  • Use this .slx model for code generation. It should resolve the rt_InitInfAndNaN linking issue. .slx models trigger the latest build system compatibility and make Simulink regenerate and track required files more accurately.
Manually Include rt_nonfinite.c/.h:If you must want use a .mdl:
  1. Go to the generated code directory (e.g., model_ert_rtw/).
  2. Check if rt_nonfinite.c is there.
  3. If not follow steps 4 to 7:
  4. Manually add rt_nonfinite.c and rt_nonfinite.h to the custom code build.
  5. In Model Configuration Parameters: Go to Code Generation > Custom Code
  6. Add rt_nonfinite.c in Source files
  7. Add rt_nonfinite.h in Include files
You need to copy these files from another working code generation project or Simulink’s internal directories.
For more information regarding "rt_InitInfAndNaN", kindly refer to the following MATLAB documentation:

Categorías

Más información sobre Programmatic Model Editing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by