Getting started with Klocwork Desktop plugin for CLion
The Klocwork plugin for CLion helps you detect and fix issues before check-in.
As of 2022.4, we recommend that if you are using a version of the CLion plugin older than 2022.4, you uninstall it before installing the latest version. You can find the version of your plugin by selecting File > Settings > Plugins, go to the Installed tab and select Klocwork Static Analysis for CLion.
Restriction: Searching for settings elements isn't currently supported.
Connect to a project or stream on the Klocwork Server
You get the most from static code analysis when you connect a small local project to a larger project or stream on the Klocwork Server. The small local project is analyzed quickly while incorporating Klocwork knowledge bases generated on the server where additional source files were analyzed (for example, shared libraries). Connecting to a server project or stream also allows you to share issue status information with the integration build analysis and among team members. You can run a standalone desktop analysis, but the analysis only derives knowledge from the local project's source files.
You perform this step only once for each project.
- In CLion, click File > Settings.
- Under Tools, select Klocwork Project Settings.
- Make sure you are connected to your Klocwork Server and click refresh under Klocwork project to select your project or stream from the list.
- Under Klocwork Build Specification, point to the location of your build specification file. You need to run kwinject to generate this file.
- Optional: You can also specify the location of your Klocwork Server Build Specification Template and relevant variables, if applicable, from this dialog.
- Parallel Analysis is enabled by default; remove this option if you want to disable it.
Analyze your code
- In CLion, open the project you want to analyze.
- Click
in the toolbar. You can also run analysis by opening the Tools menu and selecting Run Klocwork Analysis.
By default, the plugin runs analysis continuously, meaning that an analysis is triggered every time you save a file. If you prefer, you can disable this option in the Klocwork System Settings and only run the analysis manually.
When the analysis is complete, the Klocwork Issues tab shows the analysis results.
Investigate detected issues
In the Klocwork Issues tab:
- Click an issue in the list to view the source code where the issue appears.
- Use Traceback information to investigate the issue. Traceback lines link to events that contributed to the issue. Key statements that contribute to issues are marked with red rectangles and include a description of the problem.
- Get help on an issue by right-clicking the issue and selecting Show help.
Fix defects and ignore the rest
For a real defect:
- Fix the issue in your code and save your changes.
- Run the analysis by clicking
.
If the issue disappears from the list, it's fixed.
For an issue that doesn't need to be fixed:
- Right-click the issue in the list and select Change Status > Ignore.
- Enter a comment and click OK.
If you're connected to a project on the Klocwork Server, your changes are now visible to other developers, and in Klocwork Static Code Analysis. Your desktop project is also updated with any changes made by other developers. This happens even before another integration build analysis has been run.