Setting up cppcheck

To install pre-built cppcheck:

sudo apt-get update
sudo apt-get install cppcheck

In case, you want to use latest cppcheck, download and build it from the source code

tar zxvf 2.1.tar.gz
cd cppcheck-2.1
mkdir build
cd build
cmake ..

P.S: In case you are interested for cppcheck GUI use cmake -DBUILD_GUI=ON ..

sudo make install

Once installation is complete.

which cppcheck

cppcheck --version
Cppcheck 2.1

Build your cpp project with cmake and pass on an extra parameter -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE to cmake. It will produceĀ  compile_commands.json file in your build folder for the project.

Execute cppcheck -p </path/to/folder/having/compile_command.json>.

To use it in VSCode add following to the tasks.json

    "label": "Run cppCheck",
    "command": "/usr/local/bin/cppcheck",
    "args": [
    "problemMatcher": "$gcc",