Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

Options to control compiler and semantic analyzer behavior

Option Description
-cc ms | gnu specify one of the predefined compiler configurations: ms for the Microsoft cl compiler, and gnu for the gnu compiler
-cf <compiler-filter-file> specify the compiler filter file
-D <macro[=value]> /D <macro[=value]> specify macro for conditional compilation. See the following sections for more details. Note that Klocwork recognizes and analyzes GNU inline assembler directives, so it is not necessary to use the -D option with asm, __asm, or __asm__.
--disable-ms-extensions disable Microsoft C/C++ language extensions. Forces the Klocwork compiler to recognize Microsoft-specific keywords (such as __int8, __cdecl, __try) as regular identifiers. This may be useful when compiling "pure C/C++" code (for example, a platform-independent library or portable ANSI-compliant code), where language extensions are not considered important, and keywords are redefined. Added for compatibility with Microsoft 's /Za option (see more details at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_.2f.Za.2c_2f.Ze.asp).
--disable-multiline-strings disable support for multi-line string literals. Use this option to override the default Klocwork behavior with respect to multi-line string literals. GCC up to (but not including) version 3.0 allows multi-line string literals, but later versions of GCC, as well as Visual Studio C++, do not support them and generate an error and/or warning. The engine tries to automatically detect the proper compatibility mode (--enable-multiline-strings for GCC-2.x, and --disable-multiline-strings otherwise). See also the --enable-multiline-strings option.
--disable-wchar_t disable wchar_t built-in type (meaningful only for MS dialect of C++, version 2005 or later)
-e std | gnu | ms | arm | ghs | sun | wr | mw specify compiler compatibility mode. For more information, see Handling compiler compatibility issues.
--enable-altivec enable AltiVec support
--enable-for-scope enable standard compliance for scope handling (meaningful only for Microsoft dialect of C++). Specify this option if you want standard C++ behavior for "for" loops. Added for compatibility with Microsoft's /Zc:forScope option (see more details at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcrefzcforscope.asp).
--enable-multiline-strings support multi-line string literals. Use this option to override the default Klocwork behavior with respect to multi-line string literals. For more details, see the --disable-multiline-strings option above.
--enable-wchar_t enable wchar_t built-in type (meaningful only for Microsoft dialect of C++). Forces the compiler to recognize "wchart" as a built-in type (by default it is not). Added for compatibility with Microsoft's /Zc:wchar_t option (see more details at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vclrfzcwchar_t.asp).
--encoding <encoding-name> specify the encoding of the input source files. Set this option to UTF-8 if the source files contain multibyte characters (for example, Japanese).
-FI <file> /FI <file> name forced include file. Available only with the Windows version of the Klocwork compiler. Same as -include <file> ; added for compatibility with Microsoft C/C++ compiler.
--honor-std treat the C++ "std" keyword as a normal namespace (default on Windows). See How C++ namespaces are handled.
-I <dir> /I <dir> specify the path to include files. Note that this option is not recursive; you must specify each subdirectory individually, as necessary.
-idirafter <dir> specify system include path
-iframework <dir> Add the framework directory to the head of the list of directories to be searched for header files. These directories are interleaved with those specified by -I options and are scanned in a left-to-right order.
--ignore-extension allow compilation of files with non-standard extensions and header files, for example: .h .kc .genc. All files with non-standard extensions are treated as C++ files. See Notes on file extensions and compiler used.
--ignore-options <options> ignore the list of unknown options in this parameter. Use this option when you are running the Klocwork compiler in a makefile and want the Klocwork compiler to ignore options specific to your build environment. The syntax is shown in the following examples: UNIX example: make CC="kwcc --ignore-options '-Wall,-O2,-G='" Windows example (must enclose options in double quotes): kwcc --ignore-options "-Wall,-02,-G=" Note 1: Use the equal sign (=) if the option to be ignored has an argument. If it requires more than one argument, enter the number of arguments after the equal sign, for example: =2 (for two arguments). Note 2: You cannot ignore options supported by Klocwork, such as -J. Note 3: The unknown options enclosed in the quotes will be ignored no matter where they appear in the command line (not just following the --ignore-options option).
--ignore-tabs handle TAB symbol as single whitespace character
-imacros <file> accept definition of macros in <file>. Must specify full path to file. File should contain one macro definition per line, beginning with the standard form #define.
-include <file> include the contents of <file> before other files. Must specify full path to file. File should contain one include statement per line, beginning with the standard form #include.
--import-dir <dir> specify search path for #import primary headers
--instantiation-depth <value> specify maximal instantiation depth nesting. This option allows you to specify the maximal depth of instantiations — the depth at which Klocwork will stop instantiating templates. Some templates may have nested templates, and when the outer template is instantiated, the nested template should be instantiated as well. The parameter, <value>, is an integer which specifies the maximal nesting level of instantiated templates. By default, nested templates are instantiated to a depth of 50.
-iprefix <prefix> specify prefix for -iwithprefix and -iwithprefixbefore include paths
-iquote specify a non-system include path
-isysroot <dir> specify root directory for include paths
-isystem <dir> -J <dir> specify the path to system include directories. Klocwork will not count lines of code or report any issues in these files.
Note: If you are accessing a common projects_root directory on NFS, there will be differences in your compilation results if paths to system includes are different from the installation host machine. This can be prevented by explicitly stating those paths with this option.
-iwithprefix <subpath> specify system include path without prefix
-iwithprefixbefore <subpath> specify non-system include path without prefix
--keep-va-arg disable special handling of va_arg-related macros
--never-cpp do not invoke the pre-processor
Note: The following metrics are calculated during pre-processing: NOCOMMSECT, LINESCOMM, BYTESCOMM, NOMACROS, NOLOCALINC, NOSYSINC, NO3DPINC, INCLDIRECTIVES, DIRECTIVES. If you use the --never-cpp option (on preprocessed files), the values for these metrics will be zero.
-nocc compile without default defines and includes
--no-honor-std do not treat the C++ "std" keyword as a namespace (default on Unix). See How C++ namespaces are handled.
--no-path-cache do not cache include directories
--no-resolve-path By default, kwbuildproject resolves symbolic links. If you specify this option, symbolic links will not be resolved for the project.
-nostdinc do not search for system includes
--pack-struct= <alignment> specify the maximum alignment value. Klocwork validates that the value is a non-negative integer that the value is a small power of two: 1, 2, 4, 8, or 16.
--override-file <file> specify an override file. See Tuning C/C++ analysis.
--size-of-types <file> Use the specified "size-of-types" file to calculate the following metrics: BYTESGLDATADECL, BTYESDATADECL, BYTESLOCDECL, BYTESPARMS, BYTESPAROTHER. If the sizes of types in your system are the same as the defaults, you do not need to create and use this file. For more information, see Specifying sizes for built-in types.
--sysroot=<dir> specify root directory for include paths
--target-platform specify target platform (defines set of default knowledge bases)
-Tc <file> /Tc <file> compile this file as C-language file
-TC /TC compile all files as C-language files
-Tp <file> /Tp <file> compile this file as C++-language file
-TP /TP compile all files as C++-language files
-trigraphs enable trigraph support
-U <macro> /U <macro> undefine the specified macro
/u do not use predefined macros. Available only with Windows version of the Klocwork compiler. Same as -undef; added for compatibility with Microsoft C/C++ compiler.
-undef do not use predefined macros
--windows enable conventions for parsing Microsoft Windows source code (default when running on Windows platform). This option overrides the -e option. See Handling compiler compatibility issues.
-x <language> specify the language of the input files. If you want to change the default compiler used (C or C++) for your source files, use this option to set the language. Use "c" for the C compiler, and either "c++" or "cxx" for the C++ compiler. See also Notes on file extensions and compiler used.
-X /X do not search for system includes. Available only with the Windows version of the Klocwork compiler. Same as -nostdinc; added for compatibility with Microsoft C/C++ compiler.
-Zc:<arg> /Zc:<arg> C++ language conformance, where <arg> can be either forScope or wchar_t[-]

Notes on file extensions and compiler used

Consult the following table to determine which compiler will be used by default for your source files:

Platform File extensions Default compiler
UNIX .c C compiler
.C, .cc, .CC, .cpp, .CPP, .cxx, .CXX, .c++, .C++ C++ compiler
Windows .c, .C C compiler
.cc, .CC, .cpp, .CPP, .cxx, .CXX, .c++, .C++ C++ compiler

To change the default compiler, use the -x compiler option, which allows you to specify the language of the input files. See Options to control compiler and semantic analyzer behavior.

If your source files have extensions that do not appear in the table above, use the --ignore-extension compiler option. The C++ compiler is used for all files with non-standard extensions. See Options to control compiler and semantic analyzer behavior.

Handling compiler compatibility issues

The Klocwork compiler compiles differently on Windows and UNIX. On Windows, the default compiler is CL (the Microsoft Visual Studio C/C++ compiler). On UNIX, the default compiler is GNU gcc (for C) and g++ (for C++).

The -e and --windows compiler options allow you to handle compiler compatibility issues:

  • The -e option specifies the compiler compatibility mode, controlling which parser is used
  • The --windows option enables Windows source file convention parsing (overriding the -e option).
Compiler compatibility mode Enables the following extensions supported by Klocwork:
std standard
gnu GNU
ms Visual C++
arm ARM
ghs Green Hills compiler
sun Sun
wr Wind River diab
mw Metaware ARC

If you are compiling your source files on Unix, the --windows option enables the following:

  • the Visual C++ extensions supported by Klocwork (equivalent to setting -e ms)
  • Windows-specific macros. The Visual C++ specific-macros defined by --windows are _WIN32, _M_IX86, and _MSC_VER.
  • case-insensitive search for include files in the preprocessor. When cross-compiling Visual C++ on Unix, case insensitivity is required. It is not required on Windows (and is not enabled in the Windows version of the Klocwork compiler).

How C++ namespaces are handled

The Klocwork C/C++ compiler, kwcc, automatically determines how it should process source files so that C++ namespaces are handled properly on both Windows and Unix.

Klocwork sets the default behavior according to the parser dialect being used. The parser dialect is set with the -e option of kwcc. For -e gnu, the default std setting is --no-honor-std . For -e ms, -e arm, and -e std, the default setting is --honor-std.

If the parser dialect has not been set, Klocwork calculates the parser dialect at runtime, and sets the value for std accordingly: on Windows, the default behavior is to distinguish std and anonymous C++ namespaces. On Unix, the default behavior is to mix std and anonymous C++ namespaces.

These defaults support the way that the std namespace is implemented in the GNU gcc compiler, version 2.95.3 and earlier. In these versions of gcc, the std namespace is mixed with the default (anonymous) namespace. This means that all names searched for in the anonymous namespace are also searched for in the std namespace, and vice versa. In addition, certain STL templates that should be in the std namespace are located in the anonymous namespace in gcc headers.

However, if you need to override the default settings, you can pass one of the following options to kwbuildproject through the option --add-compiler-options:

  • --honor-std causes kwbuildproject to treat the C++ "std" keyword as a normal namespace
  • --no-honor-std causes kwbuildproject not to treat the C++ "std" keyword as a namespace