Click here to Skip to main content
15,038,237 members
Articles / Programming Languages / C++
Posted 8 Oct 2012


12 bookmarked

Poor Man’s Visual Studio Cppcheck Integration

Rate me:
Please Sign up or sign in to vote.
4.92/5 (8 votes)
9 Oct 2012CPOL2 min read
Simple and free Cppcheck integration into Visual Studio.


Cppcheck is a good tool to have in your arsenal. Anything that helps me avoid stupid mistakes is very welcome. The problem is that if you use Visual Studio, you either have to use the separate Cppcheck GUI or pay an arm and a leg for something like Visual Lint. If you want a more convenient way to run Cppcheck on your code, but don't want to shell out $200 for the privilege, there's a fairly easy way to do a simple integration.

This article is a re-post from

Getting Started

First things first, download the latest version Cppcheck from and install it. This will give you both the command line version and the GUI version of Cppcheck.

Create a Visual Studio External Tool

In Visual Studio, open menu Tools→External Tools...

Image 1

  • Click the Add button
  • Set the Title, for example Cppcheck
  • Set Command to C:\Program Files (x86)\Cppcheck\cppcheck.exe
  • Set Arguments to --quiet --verbose --template=vs $(ItemPath)
  • Set Initial Directory to $(ItemDir)
  • Make sure Use Output window checkbox is enabled
  • Click on the Move Up button repeatedly until your entry is at the top of the list, this will make it easier to identify you new command as you can count on it being called Tools.ExternalCommand1
  • Click OK.

Voila!  You now have a Cppcheck entry in your Tools menu:

 Image 2

Use the Tool

You can now use select the Cppcheck menu entry any time you want to run Cppcheck on a file.  The cool thing about the --template=vs switch is that you can click on a Cppcheck error and Visual Studio will automatically take you to that line of code:

Image 3

Automate Cppcheck to Run on File Save

Now that we have created a command to run Cppcheck, we can have it run automatically after a file save:

  • Go to menu ToolsMacrosMacros IDE, this will bring up a the Macros IDE
  • On the left hand side there should be a Project Explorer panel
  • In the Project Explorer panel, double click on EnvironmentEvents module
  • Insert the following code in the module:
Private Sub DocumentEvents_DocumentSaved(ByVal Document As EnvDTE.Document) Handles DocumentEvents.DocumentSaved
    If Document.Language = "C/C++" Then
    End If
End Sub
  • Now save the module, close the Macros IDE, and you're good to go


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Aleksey Vitebskiy
Software Developer TerraGo Technologies
United States United States
No Biography provided

Comments and Discussions

Questionplug-in for visual studio 2005 Pin
Member 299120423-Apr-14 18:34
MemberMember 299120423-Apr-14 18:34 
QuestionCppcheck integration with VC2010 Pin
hari111r25-Mar-14 22:26
Memberhari111r25-Mar-14 22:26 
Questioncppcheck intgration with GIT Pin
Member 1054589223-Jan-14 20:22
MemberMember 1054589223-Jan-14 20:22 
GeneralMy vote of 5 Pin
DonChunior28-Jan-13 22:31
MemberDonChunior28-Jan-13 22:31 
QuestionGreat article! How to adjust the macro for "save all"? Pin
Pachner28-Jan-13 4:59
MemberPachner28-Jan-13 4:59 
AnswerRe: Great article! How to adjust the macro for "save all"? Pin
Aleksey Vitebskiy29-Jan-13 4:52
MemberAleksey Vitebskiy29-Jan-13 4:52 
GeneralMy vote of 5 Pin
DrABELL9-Oct-12 7:23
professionalDrABELL9-Oct-12 7:23 
GeneralMy vote of 5 Pin
Anna-Jayne Metcalfe8-Oct-12 4:39
MemberAnna-Jayne Metcalfe8-Oct-12 4:39 
QuestionGood article Pin
Anna-Jayne Metcalfe8-Oct-12 4:35
MemberAnna-Jayne Metcalfe8-Oct-12 4:35 
AnswerRe: Good article Pin
Aleksey Vitebskiy8-Oct-12 5:37
MemberAleksey Vitebskiy8-Oct-12 5:37 
GeneralRe: Good article Pin
Anna-Jayne Metcalfe8-Oct-12 5:54
MemberAnna-Jayne Metcalfe8-Oct-12 5:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.