Fix Polyspace Compilation Errors Related to #error Directive
Issue
The #error directive is used in C/C++ code to trigger a fatal error in case certain macros are not defined. Sometimes, the macros might be implicitly defined by your compiler to trigger execution of platform or compiler-specific code.
If you setup a Polyspace® analysis manually, you have to explicitly specify your compiler and in some cases, explicitly define the macros. Otherwise, you might see an error during Polyspace analysis with a message containing a #error directive. For instance, the following message might appear:
#error directive: !Unsupported platform; stopping!For instance, in the following example, the #error directive is reached only if the macros __BORLANDC__, __VISUALC32__ or __GNUC__ are not defined. If you use a GNU® C compiler, for instance, the compiler considers the macro __GNUC__ as defined and the error does not occur. However, if you use the default Polyspace compilation with a generic compiler, it does not consider the macros as defined.
#if defined(__BORLANDC__) || defined(__VISUALC32__)
#define MYINT int
#elif defined(__GNUC__)
#define MYINT long
#else
#error !Unsupported platform; stopping!
#endif
Possible Solutions
Automate Analysis Configuration
The compilation phase of a Bug Finder or Code Prover analysis emulates your actual compilation using the source files and options that you specified during analysis. To make sure that the sources and Polyspace analysis configuration accurately reflect your actual compilation, create the Polyspace project or options file from your compilation or build command. For more information on creating from build command, see Configure Sources and Build Options in Project for Polyspace Analysis and Testing.
If your build command is not supported for automatic project creation, you might be creating a project manually. If you encounter the error during manual build of a project, try to trace the error to one of the following causes and apply appropriate fixes.
Check Compiler
Check if the compiler specified during Polyspace analysis matches the compiler you use for building your sources. For more information on the Polyspace option for compiler specification, see Compilation toolchain (Static Analysis).
Define Macro
If the macro does not correspond to a compiler specification or cannot be defined using an existing Polyspace option, you can define the macro explicitly for Polyspace analysis. For more information on the Polyspace option for defining macros, see Preprocessor definitions (-D).
See Also
Compilation toolchain (Static Analysis) | Preprocessor definitions (-D)