Getting started in Visual Studio for C/C++ projects

From current

Desktop analysis > Visual Studio C/C++ > Getting started in Visual Studio for C/C++ projects

Contents

Prerequisites and setup considerations

Installation

Before you can analyze your source code, you need to install the Klocwork User package.

An integration project to connect to

Connected desktop is a key step in harnessing the power of Insight. Before you can connect, an integration project must be set up and analyzed on the Klocwork Server. For more information about integration projects, see Integration build analysis.

If you don't connect to an integration project, this is referred to as standalone desktop.

Connect to a project on the Klocwork Server

Note: If you see a login dialog, enter the credentials provided by your Klocwork administrator, or your LDAP or NIS user name and password. See Authentication dialog in Visual Studio.

You can connect to an integration project on the Klocwork Server to share analysis results, issue-status updates, and comments with the system-build analysis and among team members.

Note: If your solution contains both C/C++ and C# projects, you'll need to connect your solution with two projects on the Klocwork Server--a C/C++ integration project and a C# integration project. For more information, see Analyzing mixed C/C++ and C-sharp projects. Connecting to both integration projects ensures that C/C++ and C# issues are synchronized between the server and the desktop.

Contact your Klocwork administrator for more information about available server projects.

  1. Right-click a solution in the Solution Explorer and select Klocwork Properties.
    Troubleshooting: Can't see Klocwork Properties in the menu? See Cannot access Klocwork Properties in Visual Studio.
    The Klocwork Properties dialog appears.
  2. In the Klocwork Project list, select the integration project you want to connect to.
    Optional: To view an updated list of integration projects on the Klocwork Server, click the Refresh button.
  3. Click OK.
    Tip: You only have to do this step once, before your first analysis for a project.

Access a file to work on

With on-the-fly analysis, issues are detected as you type, so that you can address them right away.

Issue highlighting:

When one or more issues are detected in the file, you see issue markers on the left and right margins of the editor. The left markers (chevrons) scroll with the text. You can use both the left and right markers to navigate to detected issues in the file. However, use the markers on the right to navigate without the need to scroll through the file.

Note: When there is more than one issue on the same line, the left gutter markers will only display the highest priority issue on the line.

The markers are color-coded according to issue severity:

Left margin icon Right margin icon Severity
Red chevron.png Red bar.png Critical, Error
Yellow chevron.png Yellow bar.png Warning, Review

Tips:

  • You can disable the left-margin icons and text underlining in the General Options dialog in Visual Studio. The underlining is also color-coded according to severity.
  • By default, Insight shows all detected issues whether their origin is Local or System. Local issues are those you've introduced since the last integration build analysis; System issues are those that exist in the integration build and the desktop analysis.
  • You can filter issues by severity, owner and taxonomy.

Notes:

  • By default, on-the-fly analysis is enabled for C/C++ Klocwork solution. However, it is not supported for C# projects. For mixed projects (a solution containing C/C++ and C# projects), you will need to analyze the project or solution to detect C# issues. A full project or solution analysis will detect both C/C++ issues and C# issues.
  • Header analysis issues are detected as on-the-fly analysis is run. For more, see Header analysis in Visual Studio.

Review and investigate

In the Klocwork Issue window, you can:

  • Group by VS group by taxonomy.png taxonomy, VS group by file.png file, VS group by severity.png severity, or VS group by code.png issue code.
Note: If you've grouped by taxonomy and the same issue was detected in each taxonomy, you'll see that issue listed twice (in each applicable taxonomy). This is the only time you'd see the same issue listed twice. Grouping by taxonomy allows you to focus only violations of a particular standard.
  • Filter issues by Severity, Owner and Taxonomy.
  • Filter to show only local issues VS show local issues.png.
  • Filter to show issues only in the active file VS show active file.png.
  • Double-click an issue in the list to see it in source code and to view traceback.
    Traceback identifies and describes statements in the source code that contribute to issues. Traceback lines link directly to the source code and follow execution order.
    Click the traceback statements to find problems that led to the issue you are viewing in the list. Key statements that contribute to issues are marked with red rectangles and include a description of the problem.
    Tip: Traceback may not be available for all issues. If you don’t see any traceback for the error selected from the list of issues, it means that the problem associated with the issue is confined to one line of code.
  • Get help on an issue by selecting it and clicking F1.

Troubleshooting

Fix the defects and ignore the rest

Now that you have had a chance to analyze your code and investigate the issues, it's time to deal with your defects. Double-click the defect you want to address in the issue list. This will bring you to the line of the file where the defect is located. Apply the necessary fix and the defect will disappear as soon as you are finished typing the correction.

If there's any issue that you don't care about, you can change it's status to Ignore.

  1. Right-click an issue in the list or the red Red chevron.png or yellow Yellow chevron.png chevron icon in the left gutter and select Ignore defect.
  2. The issue disappears from your issue list.

The list of issues updates to reflect the changes you made.

If you're connected to a project on the Klocwork Server, your changes are now visible to other developers, and in Klocwork Review. Your desktop project is also updated with any changes made by other developers. This happens even before another integration build analysis has been run.

What's next?

Now that you've run your first Klocwork Insight desktop analysis, you may want to check out additional help resources:

See also

Visual Studio troubleshooting