Friday, March 2, 2012

How to install cppcheck and use it in Eclipse CDT

I have to thank my colleague Dani for this post.

Cppcheck is an static analysis tool for C/C++ code that we are using at work.
It's helping us to detect some problems that the compiler can not detect.

1- Install cppcheck:
  • Go to cppcheck project site and download the current version of cppcheck.
  • Untar it and compile it (e.g. "make" in the corresponding folder).
  • Move it to a convenient folder (e.g. /home/bscuser/ )
2- Install the cppcheclipse plugin to use cppcheck from Eclipse:
  • In Eclipse, go to Help > Eclipse Marketplace
  • Look for "cppcheclipse" in the bar and click in "install"
3- Configure it:
  • In Eclipse, go to Window > Preferences. In the C/C++ > cppcheclipse select the binary path (e.g. /home/bscuser/cppcheck-1.52/cppcheck)
Now we are going to configure cppcheclipse for this particular project.
The next menus can be found in Eclipse, go to Project > Properties.
  • The configuration in the cppcheclipse menu can be found in the following snapshot:
  • In cppcheclipse > Problems choose "Use project settings" and unselect "portability" (we are still not interested in this point). Keep the other ones selected.
4- Run it!
  • In the Project Explorer (by default at the left of the screen) right click on "src" and select cppcheck > Run cppcheck. Alternatively, use the shortcut: Shift + Ctrl + c.
The results are prompt in an alternative Console. To see them click on "Display Selected Console" and choose the "cppcheck" one, or open a new one with the "Open Console" button.
Have fun!

No comments:

Post a Comment