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

Alternate build integration methods for Visual Studio C/C++ projects

Alternate build integration methods for Visual Studio C/C++ projects

kwinject creates the most accurate build specification and is the recommended build integration method for all C/C++ projects, including Visual Studio projects built from the command line (with devenv, msdev, vcbuild or msbuild). However, if you are unable to create a build specification for your Visual Studio C/C++ project with kwinject, this article explains alternate build integration methods.

Before you begin: Build your Visual Studio project in Visual Studio before you attempt to create a Klocwork build specification. Building in Visual Studio first ensures that your project is properly set up, and that any files generated "on the fly" are available to the Klocwork tools.

To create a build specification for a project with a .dsp, .dsw, .vcproj or .sln file, run kwdspparser or kwvcprojparser.

If your Visual Studio project contains multiple platforms, you must specify the full configuration, including the platform. For example:

kwvcprojparser project.vcproj -c "Debug|Itanium"

Creating a build specification for multiple .dsp or .vcproj files

You cannot specify more than one Microsoft Visual Studio project file per project. As a workaround, create a top-level solution or workspace file and use it to create your Klocwork project.

To generate a build specification for multiple .dsp or .vcproj files:

  1. In Visual Studio, create a new workspace (solution) file and add your existing projects to it (.dsp or .vcproj files).
  2. Make sure the settings are correct by building the Visual Studio project in Visual Studio. This ensures that your project is properly set up, and that any files generated "on the fly" are available to the Klocwork tools.
  3. If necessary, define the dependencies between your projects. If there are dependencies, follow the dependency rules (for example, executable linking a static library depends on the static library). If the modules are independent, pick one project as the main project and make it depend on all the other ones.
  4. Use kwdspparser or kwvcprojparser to generate a build specification.

Visual Studio 6 example

This example uses Visual Studio 6 with the open-source project WinCVS.

Note: Our sample project contains a .dsp project file, so we're using the kwdspparser command to generate a build specification. If your project has a .vcproj file instead, use the kwvcprojparser command.

To gather information about the WinCVS software system and create a build specification:

  1. Change the working directory to the top-level source directory in WinCVS that contains the .dsp file. For example:
    cd C:\WinCvs2_0_2_4_Src\WinCvs
    
  2. View a list of possible configurations with the --list-configs option of kwdspparser:
    kwdspparser <dsp-file> --list-configs
    
    For example:
    kwdspparser wincvs.dsp --list-configs
    
  3. You see output resembling the following (after the copyright information):
    Processing "C:\WinCvs2_0_2_4_Src\WinCvs\wincvs.dsp"...
    Possible configurations are:
    - "Release"
    - "Debug"
  4. Run the parser on the project file:
    kwdspparser <dsp-file> -c <config-name> [-o <output-file>]
    
    We'll use the Debug configuration in this example, and specify it with the -c option.
    We'll use the -o option to specify the name and location of the build specification file. By default, it is named <dsp-file>.out, and is saved in the current working directory.
    For example:
    kwdspparser wincvs.dsp -c Debug -o "C:\Program Files\Klocwork\projects_root\config\wincvs2_0_2_4.out"
    
  5. Output resembling the following appears (after the copyright information):
    Processing configuration "Debug" in project "C:\WinCvs2_0_2-4_Src\WinCvs\wincvs.dsp"...
    The project's build specification has now been saved to the specified location.

Support for Visual Studio built-in macros

kwvcprojparser and kwdspparser include support for Visual Studio built-in macros.

Visual Studio substitutes environment variables of the form $(VARIABLE). Built-in Visual Studio macros and environment variables are expanded in the same manner. Most of the built-in macros are directly supported by the parsers. In the unlikely case that you encounter an unsupported macro, you see a message like the following:

Processing configuration "Release|Win32" in project "f:\CVSREPOSITORY\Klocwork-HEAD\sources\remote_cxx\kwdistadmin.vcproj"... Warning: Environment variable "$(Klocwork_HOME)" is not set

In such cases, define this variable in your environment. The easiest way is to open a command prompt and issue the following command:

Set Klocwork_HOME=<your value>

The value of the variable depends on the usage.

In addition, the kwvcprojparser option /useenv instructs the parser to use the INCLUDE environment variable. Note that all paths specified in the INCLUDE environment variable are specified as "system includes" in the resultant build specification, and override any Visual Studio .NET 2003, 2005 or 2008 settings set in Tools > Options > Project > VC++ Directories.

Note that kwdspparser does not have this functionality, and always uses Visual Studio 6 settings.