Intel® oneAPI DPC++/C++ Compiler
Talk to fellow users of Intel® oneAPI DPC++/C++ Compiler and companion tools like Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and Intel® Distribution for GDB*
627 Discussions

Using _matherr results in a compilation error, Windows, VS 2019

BjörnTR
Beginner
337 Views

Hello,

I am attempting to swap from an old version of ICL, to ICX. However I am running into a problem with _matherr.

I am running ICX without any arguments in a command line after having called "C:\Program Files (x86)\Intel\oneAPI\setvars.bat". VS2019INSTALLDIR has been set manually on this computer, as it seems to no longer get set automatically.

 

error: conflicting types for '_matherr'
21 | int __CRTDECL _matherr(_Inout_ struct _exception* _Except)
| ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_math.h(527,19): note: previous declaration is here
527 | int __CRTDECL _matherr(_Inout_ struct _exception* _Except);

I have tried to simplify the problem by using the examples provided by Microsoft for this feature, as well as one other source. But I get the same error.

One difference I know of is that the old ICL doesn't include the same set of files as ICX does, (the INCLUDE variable from the environment variables, with ; replaced with newline for readability).

Is this a bug with the compiler? Or is this feature simply not available or works differently?

Any and all help is appreciated!

Best regards,
Björn

 

 

 

C:\Program Files (x86)\Intel\oneAPI\tbb\latest\env\..\include
C:\Program Files (x86)\Intel\oneAPI\ocloc\latest\include
C:\Program Files (x86)\Intel\oneAPI\mpi\latest\env\\..\include
C:\Program Files (x86)\Intel\oneAPI\mkl\latest\include
C:\Program Files (x86)\Intel\oneAPI\ippcp\latest\include
C:\Program Files (x86)\Intel\oneAPI\ipp\latest\include
C:\Program Files (x86)\Intel\oneAPI\dpcpp-ct\latest\env\..\include
C:\Program Files (x86)\Intel\oneAPI\dev-utilities\latest\include
C:\Program Files (x86)\Intel\oneAPI\compiler\latest\include
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\ATLMFC\include
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include
C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt

 

 

 

Vs 

 

 

 

c:\Program Files (x86)\Intel\Composer XE 2011 SP1\compiler\include
c:\Program Files (x86)\Intel\Composer XE 2011 SP1\compiler\include\intel64
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\INCLUDE
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ATLMFC\INCLUDE
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include
c:\Program Files (x86)\Intel\Composer XE 2011 SP1\ipp\include
c:\Program Files (x86)\Intel\Composer XE 2011 SP1\mkl\include
c:\Program Files (x86)\Intel\Composer XE 2011 SP1\tbb\bin\..\include
/* crt_matherr.c
* Illustrates writing an error routine for math
* functions. 
* The error handling function must be named _matherr
*/

#include <math.h>
#include <string.h>
#include <stdio.h>

int main()
{
    /* Do several math operations that cause errors. The _matherr
     * routine handles _DOMAIN errors, but lets the system handle
     * other errors normally.
     */
    printf( "log( -2.0 ) = %e\n", log( -2.0 ) );
    printf( "log10( -5.0 ) = %e\n", log10( -5.0 ) );
    printf( "log( 0.0 ) = %e\n", log( 0.0 ) );
}

/* Handle several math errors caused by passing a negative argument
* to log or log10 (_DOMAIN errors). When this happens, _matherr
* returns the natural or base-10 logarithm of the absolute value
* of the argument and suppresses the usual error message.
*/
int _matherr(struct _exception *except)
{
    /* Handle _DOMAIN errors for log or log10. */
    if (except->type == _DOMAIN)
    {
        if (strcmp(except->name, "log") == 0)
        {
            except->retval = log(-(except->arg1));
            printf("Special: using absolute value: %s: _DOMAIN "
                     "error\n", except->name);
            return 1;
        }
        else if (strcmp(except->name, "log10") == 0)
        {
            except->retval = log10(-(except->arg1));
            printf("Special: using absolute value: %s: _DOMAIN "
                     "error\n", except->name);
            return 1;
        }
    }
    printf("Normal: ");
    return 0;    /* Else use the default actions */
}

 

 

 

From: _matherr | Microsoft Learn

0 Kudos
3 Replies
Alex_Y_Intel
Moderator
278 Views

Have you installed Intel's oneAPI base toolkit and successfully integrate it with your Visual Studio 2019 or 2022? If so, you'll find "Intel oneAPI command prompt for Intel 64 for Visual Studio 20xx" and from there you don't need to run the setvars.bat since everything will be loaded correctly when you start the prompt. 

https://www.intel.com/content/www/us/en/developer/articles/guide/installation-guide-for-oneapi-toolkits.html

I can run your program fine on my system--

C:\Users\Project12>icpx test.cpp

C:\Users\Project12>dir
Volume in drive C is IntelBuild
Volume Serial Number is D848-CB49

Directory of C:\Users\Project12

05/09/2024 04:39 PM <DIR> .
05/09/2024 04:37 PM <DIR> ..
05/09/2024 04:39 PM 180,224 a.exe
05/09/2024 04:38 PM 1,560 test.cpp
2 File(s) 181,784 bytes
2 Dir(s) 539,051,417,600 bytes free

C:\Users\Project12>a.exe
log( -2.0 ) = -nan(ind)
log10( -5.0 ) = -nan(ind)
log( 0.0 ) = -inf

0 Kudos
BjörnTR
Beginner
219 Views

I have integrated it with VS as far as I know, and even when starting it from that command prompt I get the same error. 

However I have also been able to successfully compile this, but only by doing what you have done, use ICPX instead of ICX. Perhaps this function is only intended to work with C++?  From what I can tell by the documentation I can find on this feature, it seems to be part of the C runtime, so I would expect it to work with C code, (ICL).

Here is my output:

C:\Test>icx test.c
Intel(R) oneAPI DPC++/C++ Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

C:\Test\test.c(27,5): error: conflicting types for '_matherr'
27 | int _matherr(struct _exception* except)
| ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_math.h(527,19): note: previous declaration is here
527 | int __CRTDECL _matherr(_Inout_ struct _exception* _Except);
| ^
1 error generated.

C:\Test>dir
Volume in drive C has no label.
Volume Serial Number is 

Directory of C:\Test

2024-05-14 09:41 <DIR> .
2024-05-14 09:37 1 539 test.c
2024-05-14 09:37 1 539 test.cpp
2 File(s) 3 078 bytes
1 Dir(s) 164 194 922 496 bytes free

C:\Test>icpx test.cpp

C:\Test>dir
Volume in drive C has no label.
Volume Serial Number is 

Directory of C:\Test

2024-05-14 09:43 <DIR> .
2024-05-14 09:43 175 104 a.exe
2024-05-14 09:37 1 539 test.c
2024-05-14 09:37 1 539 test.cpp
3 File(s) 178 182 bytes
1 Dir(s) 164 194 476 032 bytes free

0 Kudos
Alex_Y_Intel
Moderator
196 Views

Actually, when you use Intel compiler on Windows, icx is recommended regardless of your source code is c. or .cpp file. icx is the MSVC compatible driver.  Although the use of icpx  is there for Windows, icpx is the Linux compatible driver, which means it accepts the Linux style options, but the behavior targets Windows-based targets.

Anyways, the problem is hinted in your error message: 
error: conflicting types for '_matherr'
21 | int __CRTDECL _matherr(_Inout_ struct _exception* _Except)
| ^
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt\corecrt_math.h(527,19): note: previous declaration is here
527 | int __CRTDECL _matherr(_Inout_ struct _exception* _Except);

 

The _matherr is defined in two different places, one in your source code, another in corecrt_math.h. If you save your source code as .cpp file compile without the problem is because C++ has a name-mangling mechanism to avoid this issue, while C does not.

However, since clang-cl can solve this issue but icx cannot, I'm escalating your issue to our internal team, and will come back with update when we reach the conclusion.  


0 Kudos
Reply