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.htm/_core_.2f.Za.2c_2f.Ze.asp). |
--disable-multiline-strings | disable support for multi-line string literals. |
--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.htm/vcrefzcforscope.asp). |
--enable-multiline-strings | enable support for multi-line string literals. |
--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.htm/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). |
-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-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. 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 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). |
--no-lef, -n | do not run the Klocwork issue detection stage |
--no-path-cache | do not cache include directories |
--no-resolve | by default, kwbuildproject resolves symbolic links. If you specify this option, symbolic links to files will not be resolved for the project, but symbolic links to directories will be resolved. |
--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 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 that your compiler uses.