Qodana for C/C++
Qodana for C/C++ lets you analyze C and C++ projects containing compilation databases. This linter is based on the Clang-Tidy linter and works on the AMD64 and ARM64 architectures.
Qodana for C/C++ extends the existing Clang-Tidy inspections by supplying the Clang-Tidy and MISRA checks inspections provided by CLion.
Qodana for C/C++ is available under the Community, Ultimate, and Ultimate Plus licenses. However, the Clang-Tidy and MISRA checks inspections from CLion are available only under the Ultimate and Ultimate Plus licenses.
Supported features
The Qodana for C/C++ linter provides the following Qodana features:
Feature | Available under licenses |
|---|---|
Community, Ultimate and Ultimate Plus | |
Community, Ultimate and Ultimate Plus |
How it works
The Docker image of Qodana for C/C++ employs Clang 16.0.0 and LLVM 16. You can see the Dockerfile for the detailed description of all software employed by the linter.
The linter searches for the compilation database file contained in the build/compile_commands.json file of the project directory and reads this file, analyzes the project, generates analysis reports, and saves them locally or uploads to Qodana Cloud.
Prepare the project
Make sure that Clang-Tidy is deployed on your system. If necessary, install it using the LLVM website.
Open the
qodana.yamlfile and use theincludeandexcludeconfiguration options to configure the list of inspections. Alternatively, you can configure inspections in the.clang-tidyfile, see the configuration example on the GitHub website. After configuring, save this file under the project root.Open the
.clang-tidyfile and configure the list of files and paths that will be analyzed by Qodana for C/C++.Generate the
compile_commands.jsonfile as explained in the CLion documentation portal, and save it to thebuilddirectory under the project root.If you use CMake, you can also generate a compilation database by specifying the following
bootstrapoption in theqodana.yamlfile, for example:bootstrap: mkdir -p build; cd build;cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. || trueIf your project requires specific packages not previously mentioned in the
Dockerfile, add the followingbootstrapcommand to yourqodana.yamlfile to install the required packages:bootstrap: sudo apt-get update; sudo apt-get install -y <list of required packages> | rm -rf build; mkdir -p build; cd build;cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON .. || true
Run Qodana for C/C++
Run the following Docker command:
The linter will read the build/compile_commands.json file and run the Clang-Tidy tool.
In this command, the QODANA_TOKEN variable refers to the project token that lets you upload inspection results to Qodana Cloud. If you omit the QODANA_TOKEN variable, the inspection results will be available in the qodana.sarif.json saved in the /results directory of your project root.
To override the location of a compilation command database, you can specify the location for the compile_commands.json file relatively to the project root, so the Docker command will look like: