Failed to convert matlab function to dll
Show older comments
I was using matlab coder to convert my matlab function to dll. It converted to C code successfully but failed when compiling to dll. Target Build Log:
D:\Myfolder\codegen1\rt_nonfinite.c(21): error C2099: initializer is not a constant
D:\Myfolder\codegen1\rt_nonfinite.c(24): error C2099: initializer is not a constant
NMAKE: fatal error U1077: 'cl -c -nologo -GS -W4 -DWIN32 -D_MT -MT -D_CRT_SECURE_NO_WARNINGS /O2 /Oy- /source-charset:utf-8 -DMODEL=Recoil @Recoil_rtw_comp.rsp -Fo"rt_nonfinite.obj" "D:\Research\Achievement\RecoilCFD\FHZ30\Solve\matlabdll\codegen1\rt_nonfinite.c"' : return code '0x2'
Stop.
The make command returned an error of 2
I checked the rt_nonfinite.c and found that these lines:
#include "rt_nonfinite.h"
#include <math.h>
#if defined(__ICL) && __ICL == 1700
#pragma warning(disable : 264)
#endif
real_T rtNaN = (real_T)NAN;
real_T rtInf = (real_T)INFINITY;
real_T rtMinusInf = -(real_T)INFINITY;
real32_T rtNaNF = (real32_T)NAN;
real32_T rtInfF = (real32_T)INFINITY;
real32_T rtMinusInfF = -(real32_T)INFINITY;
NAN and INFINITY is not constant and they actually identified by compiler as function, which defined in corecrt_math.h
Anybody know how to solve this problem?
Thank you!
Answers (1)
Walter Roberson
on 3 May 2025
NAN and INFINITY is not constant and they actually identified by compiler as function, which defined in corecrt_math.h
In C, there is no automatic calling of functions. References to function names that do not include () to call the function, are semantically invalid unless proceeded by & .
But suppose naming the function without & or () were equivalent to taking the address of the function. Then your (real_T)NAN would be coercing the address of NAN to be real_T which is obvious nonsense.
At the very least you will need to provide function call syntax,
real_T rtNaN = (real_T)NAN();
real_T rtInf = (real_T)INFINITY();
real_T rtMinusInf = -(real_T)INFINITY();
real32_T rtNaNF = (real32_T)NAN();
real32_T rtInfF = (real32_T)INFINITY();
real32_T rtMinusInfF = -(real32_T)INFINITY();
Categories
Find more on Algorithm Design Basics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!