Intel compiler on Windows bug workarounds
There is a tension between the Visual Studio point release and Intel compilers on Windows. The issue arises from Visual Studio frequently updating, and Intel compiler falling behind with the Intel compiler to Visual Studio ABI. This can cause strange and unpredictable errors when compiling a C program, for example
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.23.28105/include/vcruntime_string.h(18): error: expected an attribute name
_NODISCARD _Check_return_
Workaround
Intel support
notes
that a workaround is to force C++ compiler to be used with the /Tp<source_filename>
option.
Meson
In Meson, this workaround can be applied in meson.build like:
cc = meson.get_compiler('c')
if cc.get_id() == 'intel-cl'
add_project_arguments('/TP', language: 'c')
message('applying workaround for Intel ICL bug with MSVC: https://www.scivision.dev/intel-compiler-windows-bug-workaround')
endif
CMake
In CMake, this workaround can be applied in CMakeLists.txt like:
if(WIN32 AND CMAKE_C_COMPILER_ID STREQUAL Intel)
add_compile_options(/TP)
message(STATUS "applying workaround for Intel ICL bug with MSVC: https://www.scivision.dev/intel-compiler-windows-bug-workaround")
endif()