Problem compiling with Intel C compiler via MATLAB Coder
Show older comments
I have registered a toolchain that uses the Intel C compiler (icc), but compilation fails because icc does not recognize NAN and INFINITY in the file rt_nonfinite.c. The problematic lines are
real_T rtNaN = (real_T)NAN;
and
real_T rtInf = (real_T)INFINITY;
I thought I had solution when I added
tc.addMacro('C_STANDARD_OPTS',' -D__PURE_INTEL_C99_HEADERS__ ');
to my m-file defining the toolchain object. But now compilation fails due to the same lines (and more) in rt_nonfinite.c, but for a different reas on. The error is now
error: expression must have a constant value.
I know that NAN and INFINITE are defined in the math.h that comes with icc. Could icc be unaware of its own header files? How can I fix that?
Thanks in advance for advice and insight. I am working on a 64 bit Linux box.
Answers (1)
Joe M
on 25 Feb 2021
3 Comments
Ryan Livingston
on 1 Mar 2021
The setting cfg.TargetLangStandard is what controls the flavor of C or C++ code generated by MATLAB Coder. The toolchain setting
tc.addMacro('C_STANDARD_OPTS', ' -std=c11 ');
only controls flags passed to icc, it does not impact the generated code. Without knowing much about icc, I'd suspect you could use -std=c99 and still have things work as MATLAB Coder is generating C99 code.
To demonstrate, if you set
cfg.TargetLangStandard = "C89/C90 (ANSI)";
and generate code, you'll see that the references to INFINITY and NAN are gone since those were introduced in C99:
/*
* Function: rt_InitInfAndNaN ==================================================
* Abstract:
* Initialize the rtInf, rtMinusInf, and rtNaN needed by the
* generated code. NaN is initialized as non-signaling. Assumes IEEE.
*/
void rt_InitInfAndNaN()
{
rtNaN = rtGetNaN();
rtNaNF = rtGetNaNF();
rtInf = rtGetInf();
rtInfF = rtGetInfF();
rtMinusInf = rtGetMinusInf();
rtMinusInfF = rtGetMinusInfF();
}
/*
* Function: rtGetNaN
* ======================================================================
* Abstract:
* Initialize rtNaN needed by the generated code.
* NaN is initialized as non-signaling. Assumes IEEE.
*/
real_T rtGetNaN(void)
{
real_T nan = 0.0;
uint16_T one = 1U;
enum
{
LittleEndian,
BigEndian
} machByteOrder = (*((uint8_T *)&one) == 1U) ? LittleEndian : BigEndian;
switch (machByteOrder) {
case LittleEndian: {
union {
LittleEndianIEEEDouble bitVal;
real_T fltVal;
} tmpVal;
tmpVal.bitVal.words.wordH = 0xFFF80000U;
tmpVal.bitVal.words.wordL = 0x00000000U;
nan = tmpVal.fltVal;
break;
}
case BigEndian: {
union {
BigEndianIEEEDouble bitVal;
real_T fltVal;
} tmpVal;
tmpVal.bitVal.words.wordH = 0x7FFFFFFFU;
tmpVal.bitVal.words.wordL = 0xFFFFFFFFU;
nan = tmpVal.fltVal;
break;
}
}
return nan;
}
So your toolchain could consider basingthe value passed to the icc -std= based on the value of cfg.TargetLangStandard.
Ryan Livingston
on 7 Mar 2021
The root of the custom toolchain doc is here:
Which sort of GNU Make commands are you looking for info regarding?
Categories
Find more on MATLAB Coder 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!