# Cppcheck: A Static Analyzer for C and C++ That Builds From Source

> Cppcheck is a GPL-3.0 static analyzer for C and C++ that ships as source, runs a single binary over a codebase, and keeps the last push on 2026-09-21. Here is what it catches, how to build it, and where it stops.

**cppcheck-opensource/cppcheck** — static analysis of C/C++ code

- Repository: https://github.com/cppcheck-opensource/cppcheck
- Website: https://cppcheck.sourceforge.io/
- Stars: 6,758 · Forks: 1,599
- Language: C++
- License: GPL-3.0
- Published: 2026-09-22 · Updated: 2026-09-22 · Language: en
- Canonical page: https://hysenlabs.com/projects/cppcheck-opensource-cppcheck

## What Cppcheck catches that a compiler does not

Cppcheck is a static analyzer for C and C++ that parses source rather than object code. The README is explicit that the name is historical: the program began as C++check and, despite the spelling, "Cppcheck is designed for both C and C++." The repository confirms this in its topics, which list c and c-plus-plus alongside static-analysis. The samples directory is the clearest statement of intent, because it is organized by defect class: arrayIndexOutOfBounds_1 and _2, bufferAccessOutOfBounds, memleak, resourceLeak, autoVariables, unreadVariable, invalidContainer, passedByValue_1 and _2, multiCondition, incorrectLogicOperator, accessMoved, AssignmentAddressToInteger, and syntaxError.

That list tells you where the tool aims. These are defects a compiler with warnings enabled will usually let through: an index that goes out of range on one branch, a resource that leaks on an early return, a container invalidated by an operation on itself, a variable assigned but never read, a condition whose two halves cannot both be true. The audience is C and C++ developers who want a second pass over code that already compiles, and teams that want that pass to run on a build server without a full compiler toolchain per target.

It is not a compiler replacement and it is not a proof engine. Nothing in the README or the repository listing claims soundness, and the samples are single-purpose fixtures rather than a conformance suite. Treat the output as candidates for review.

## How the analyzer is put together

The repository layout separates concerns in a way worth understanding before you build. lib/ holds the analyzer core, cli/ the command-line front end, frontend/ the shared entry code, and gui/ a separate graphical application. externals/ vendors the dependencies: simplecpp for preprocessing, tinyxml2 for XML, picojson for JSON. cfg/ carries library configuration files that teach the analyzer about external APIs, platforms/ holds target data models, addons/ contains Python addons, and rules/ holds rule definitions. htmlreport/ is a separate reporting tool.

The build has a genuine fork in it. With MATCHCOMPILER=yes, several Token matching patterns are converted into more efficient C++ code at compile time, and the Makefile runs tools/matchcompiler.py to do it, which is why that path requires a Python interpreter. The Makefile searches for python3 and then python, and stops with "Did not find a Python interpreter" if neither is present. Without MATCHCOMPILER, the libcppdir variable points at lib/ directly. The header of the generated Makefile says it plainly: "This file is generated by dmake, do not edit."

Optional capabilities are compile-time decisions, not runtime flags. HAVE_RULES=yes enables rules and requires PCRE. HAVE_BOOST=yes uses a Boost container. FILESDIR sets where addons, cfg and platform files are installed. That means two binaries built from the same commit can behave differently, and a bug report that omits the build flags is hard to reproduce.

## Building Cppcheck with CMake, and a first run

The README lists CMake as the cross-platform choice, with a minimum of CMake 3.22. A C++ compiler with partial C++11 support is required, with minimum versions of GCC 5.1, Clang 3.5, AppleClang 6.0 or Visual Studio 2015. Python 3.7 is the minimum when a script needs it.

The two commands below configure and build the command-line tool. The README gives exactly this pair. After the build finishes, the binary is in the build directory, and running it with no arguments prints the usage text.

```bash
cmake -S . -B build
cmake --build build
```

For a release build the README recommends -DUSE_MATCHCOMPILER=ON, and if you want the rules engine you add -DHAVE_RULES=ON, which requires PCRE. Building the tests is a separate flag, -DBUILD_TESTING=ON. The GUI needs CMake and the flag -DBUILD_GUI=ON.

```bash
cmake -S . -B build -DUSE_MATCHCOMPILER=ON -DBUILD_TESTING=ON
cmake --build build
```

If you prefer make, the README gives a simple unoptimized build as a single command, and a recommended release build with the match compiler, an install directory, rules, optimization and assertions disabled. Note that FILESDIR controls where addons, cfg and platform files are installed, so an install that omits it will look for those files elsewhere.

```bash
make
make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes CXXOPTS="-O2" CPPOPTS="-DNDEBUG"
```

The README documents several other routes. On Windows, cppcheck.sln is configured for Visual Studio 2019 with x86 and x64 targets, and msbuild cppcheck.sln builds it from the command line; the Release-PCRE and Debug-PCRE configurations expect pcre.lib and pcre.h in /externals. MinGW uses mingw32-make. There is a VS Code extension, Cppcheck Official, maintained by the cppcheck team and linked from the README at github.com/cppchecksolutions/vscode-cppcheck-official. Cross-compiling a Win32 command-line build from Linux is documented with a mingw32 install and a make invocation setting CXX.

What the README does not give is a first analysis command. It points to the online manual for usage, and the manual is a separate PDF. So the honest sequence is: build the binary, then read the manual before pointing it at your tree.

## The donation client, and what it reveals about the project

The README has a section titled "Donate CPU" that is unusual enough to be worth reading as a design signal. The project describes itself as "a hobby project with limited resources" and asks users to contribute compute. The setup is a virtual environment, a requirements file, and a script.

```bash
cd cppcheck/
python3 -m venv .venv
source .venv/bin/activate
pip install -r tools/donate-cpu-requirements.txt
./tools/donate-cpu.py
```

The script analyses Debian source code and uploads results to a Cppcheck server. The README states the purpose directly: the results are needed "both to improve Cppcheck and to detect regressions." The -j flag controls how many cores are used, and the default is one. Ctrl+C stops it.

Read that as a statement about maintenance economics. A static analyzer is only as good as the corpus it is tuned against, and this project crowdsources that corpus from its users. The practical consequence for an adopter is that the analyzer's accuracy on your code depends on how much code like yours has been fed through it. Niche dialects, heavy template metaprogramming, or vendor-specific extensions are less likely to be well represented. That is not a defect in the tool; it is a boundary you should test against your own sources rather than assume away.

## Where Cppcheck is the wrong tool

The first limitation is visible in the build instructions. There is no documented package-manager install path in the README. The compilation section is the installation section, and it assumes a C++ toolchain, CMake 3.22 or make, and in several configurations Python 3.7 or newer. If your workflow is apt install or a container image pull, the README does not help you, and you should check whether your distribution packages it before starting.

The second is PCRE. Rules support is gated behind HAVE_RULES=yes and a PCRE dependency, and PCRE is listed as optional when building the command-line tool. A binary built without it will not have the rules engine, and nothing in the runtime tells you which optional features were compiled in unless you know the flags used. This matters for reproducibility: pin the build flags alongside the commit hash, or two engineers will compare different tools.

The third is scope. Cppcheck parses source and does not require a working build, which is why it can run on a file that does not compile. That same property means it cannot see what only the linker sees. If your defect is an ODR violation, a missing symbol, or a state machine that spans several translation units through a callback, this is not the tool that finds it. The samples are all local patterns: an index, a buffer, a leak on a path, a variable never read.

The fourth is the GPL-3.0 licence. See the licence section below for what that does and does not imply for your project.

## Cppcheck compared with clang-tidy

The natural comparison is clang-tidy, and the difference is architectural rather than a matter of check counts. clang-tidy runs inside the Clang/LLVM compilation pipeline. It needs a compilation database, typically compile_commands.json, and it sees the program with the exact type information, macro expansion and include resolution that the compiler used. Checks are organized around Clang's AST matchers, and the tool is extensible in C++ against that AST.

Cppcheck does not require a compilation database and does not need your build to succeed. It brings its own preprocessor, simplecpp, and its own parser, and it learns about external APIs from the cfg/ library files and the platforms/ data rather than from headers. That is why it can analyze a file in isolation and why it works on codebases whose build system is hostile to tooling. The cost is that its model of your types and macros is an approximation, and the cfg files need to be right for the libraries you use.

So the choice is not which one is better. If your build already produces compile_commands.json and you want checks that share the compiler's view of the code, clang-tidy fits. If you want to analyze a translation unit without building it, or you cannot produce a compilation database, Cppcheck is the one that will run. Running both is common, and the overlap in findings is a useful signal about which ones are real.

## Licence, maintenance and the cost of upgrading

Cppcheck is GPL-3.0, as stated in the README badge and the COPYING file at the repository root. The practical question for most teams is not whether you can use it internally, which the licence permits, but what happens when you redistribute it. Shipping the binary inside a product, bundling it in a container image you publish, or linking it into another tool are the cases where the copyleft terms start to matter. Static linking and combining with differently licensed code raise questions that depend on your specific distribution model. This is not legal advice; if you redistribute Cppcheck as part of a product, have counsel read the licence against your packaging.

The maintenance picture is straightforward. The repository is not archived, and the last push was on 2026-09-21, one day before this writing. Three releases appear in the recent history: 2.22.0 on 2026-09-19, 2.21.0 on 2026-06-04, and 2.20.0 on 2026-03-02. That is a roughly quarterly cadence with a patch release two days before the last push.

Upgrade cost is low if you build from source, because there is no dependency graph to reconcile beyond PCRE and optionally Boost. It is higher if you have tuned the analyzer to your codebase, since cfg files, rules and suppressions are inputs you maintain. The repository carries .selfcheck_suppressions and .selfcheck_unused_suppressions at the root, which is a useful hint: the project suppresses its own findings, and you will accumulate a similar file. Budget for reviewing that file each upgrade, because a suppression that no longer matches anything is dead weight you will not notice until it hides a real finding.

One more thing: the README opens with a note that the repository moved from github.com/danmar/cppcheck to github.com/cppcheck-opensource/cppcheck, and asks readers to update references. If your CI pins the old URL, fix it before your next build.

## Conclusion

Adopt Cppcheck if you maintain C or C++ that is compiled in more than one configuration, or if you want a checker you can build yourself and gate in CI. Do not adopt it if you need a data-flow engine that follows heap state across translation units, or if the GPL-3.0 terms conflict with how you redistribute your toolchain. Before committing, build it with -DBUILD_TESTING=ON, run it over one real module, and count how many findings survive a manual pass; that ratio decides whether it belongs in your pipeline.

## FAQ

### What is Cppcheck used for?

It is a static analyzer for C and C++ that parses source code and reports defects such as array index out of bounds, buffer access out of bounds, memory and resource leaks, unread variables and incorrect logic operators. The samples directory in the repository is organized by exactly these defect classes. It runs over code that already compiles and does not require a build.

### Is Cppcheck any good?

The README describes it as a hobby project with limited resources and asks users to donate CPU so that Debian source code can be analyzed to improve the tool and detect regressions. That is a fair signal about how its accuracy is maintained. Whether it is good enough for you depends on how many of its findings survive a manual pass over your own code.

### How do I install Cppcheck?

The README documents building from source rather than a package install. With CMake 3.22 or newer, the documented commands are cmake -S . -B build followed by cmake --build build. A C++ compiler with partial C++11 support is required, with minimum versions of GCC 5.1, Clang 3.5, AppleClang 6.0 or Visual Studio 2015, and Python 3.7 is the minimum where a script is needed.

### How do I use Cppcheck in Visual Studio?

The repository includes cppcheck.sln, configured for Visual Studio 2019 with x86 and x64 platform targets. The README notes the platform toolset can be changed to older or newer versions, and that the Release-PCRE and Debug-PCRE configurations expect pcre.lib and pcre.h to be placed in /externals. Building from the command line is done with msbuild cppcheck.sln.

### How do I use Cppcheck in VS Code?

The README points to Cppcheck Official, an extension it describes as officially supported by the cppcheck team, available through the VS Code Marketplace via the extensions tab. Setup and usage instructions are in the readme on github.com/cppchecksolutions/vscode-cppcheck-official.

### How do I use Cppcheck with CMake?

CMake 3.22 is the documented minimum. The README gives cmake -S . -B build and cmake --build build, with optional flags for the GUI (-DBUILD_GUI=ON), rules (-DHAVE_RULES=ON, requires PCRE), tests (-DBUILD_TESTING=ON) and release builds (-DUSE_MATCHCOMPILER=ON). For single-configuration generators a build type such as RelWithDebInfo is passed with -DCMAKE_BUILD_TYPE.

## Sources

- [cppcheck-opensource/cppcheck on GitHub](https://github.com/cppcheck-opensource/cppcheck)
- [License: GPL-3.0](https://github.com/cppcheck-opensource/cppcheck/blob/main/LICENSE)
- [Project website](https://cppcheck.sourceforge.io/)
- [README](https://github.com/cppcheck-opensource/cppcheck/blob/main/README.md)
- [Releases](https://github.com/cppcheck-opensource/cppcheck/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/cppcheck-opensource-cppcheck
