Build Error in Double Lane Change Reference Model: rt_nonfinite.c(5): initializer is not a constant

8 vues (au cours des 30 derniers jours)
I am working with the Vehicle Dynamics Blockset in Simulink and created the Double Lane Change Reference Application from the example library.
After clicking "Open Script" and attempting to run the model, I encountered a persistent error during code generation for the referenced model Driveline.
The build fails with the following MSVC error:
rt_nonfinite.c(5): error C2099: initializer is not a constant
NMAKE : fatal error U1077: 'cl' : return code '0x2'
I am using:
  • MATLAB R2024a
  • Simulink Coder
  • Vehicle Dynamics Blockset
  • Microsoft Visual C++ Compiler: Microsoft Visual C++ 2022 (C) (MSVC 14.3 or newer)
I’m new to this toolset. Could you please provide recommendations on how to resolve this issue or whether it’s related to compiler configuration or auto-generated code compatibility?
Thank you in advance for your support.

Réponses (1)

Shlok
Shlok le 14 Juil 2025
Hi Prakorn,
I understand you're running into a build error related to "rt_nonfinite.c" when generating code for the referenced model "Driveline". This is a known issue when using "MSVC 2022" with "Windows SDK version 10.0.26100.0".
The root cause is a change in the SDK, where NAN is no longer defined as a compile-time constant in C. Instead, it's implemented via an inline function, which causes static initializations like real_T rtNaN = NAN; in generated code (e.g., "rt_nonfinite.c") to fail with a compiler error.
In order to resolve this issue, you can try one of the following workarounds:
1. A fix for this issue seems to be included in Windows 11 SDK Build 10.0.26100.3916. Updating to this version may help resolve the problem.
2. Add the compiler flag and change the language standard:
  • Go to Model Settings > Code Generation.
  • Set Build configuration to "Specify".
  • In C Compiler and C++ Compiler present under Toolchain details, add the flag -D_UCRT_NOISY_NAN
  • Set the Language standard to "C89/C90(ANSI)" or "C++03(ISO)".
3. Switch to a different compiler:
  • Use MinGW as an alternative.
  • Or roll back to an earlier MSVC SDK version (before 10.0.26100.0).
To know more about this issue, refer to the following link:

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by