Fix Polyspace Compilation Errors Related to Visual Compilers
The following messages appear if the compiler is based on a Visual® compiler. For more information, see Compiler (-compiler)
.
Import Folder
When a Visual application uses
#import
directives, the Visual C++ compiler generates a header file with extension
.tlh
that contains some definitions. To avoid compilation errors
during Polyspace® analysis, you must specify the folder containing those files.
Original code:
#include "stdafx.h" #include <comdef.h> #import <MsXml.tlb> MSXML::_xml_error e ; MSXML::DOMDocument* doc ; int _tmain(int argc, _TCHAR* argv[]) { return 0; }
Error message:
"../sources/ImportDir.cpp", line 7: catastrophic error: could not open source file "./MsXml.tlh" #import <MsXml.tlb>
The Visual C++ compiler generates these files in its “build-in” folder (usually Debug or Release). In order to provide those files:
Build your Visual C++ application.
Specify your build folder for the Polyspace analysis.
pragma Pack
Using a different value with the compile flag (#pragma pack
) can
lead to a linking error message.
Original code:
test1.cpp | type.h | test2.cpp |
---|---|---|
#pragma pack(4) #include "type.h" |
struct A { char c ; int i ; } ; |
#pragma pack(2) #include "type.h" |
Error message:
Pre-linking C++ sources ... "../sources/type.h", line 2: error: declaration of class "A" had a different meaning during compilation of "test1.cpp" (class types do not match) struct A ^ detected during compilation of secondary translation unit "test2.cpp"
To continue the analysis, use the option Ignore pragma pack directives
(-ignore-pragma-pack)
.
C++/CLI
Polyspace does not support Microsoft® C++/CLI, a set of language extensions for .NET programming.
You can get errors such as:
error: name must be a namespace name | using namespace System;
error: expected a declaration | public ref class Form1 : public System::Windows::Forms::Form