# Parasoft C/C++test

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/clion/llms.txt).

> **TL;DR**
> 操作系统 ：Windows、Linux

可通过将 Parasoft C/C++test static 分析配置为 [外部工具](configuring-third-party-tools.html)来直接在 CLion 上运行，然后使用内置的 [SARIF 查看器](sarif-viewer-report.html)查看分析结果。

CLion 会调用 C/C++test 命令行启动器（  `cpptestcli` ），它会读取 CLion 生成的编译数据库（  `compile_commands.json` ），并将报告写入项目中。

## 先决条件

* Parasoft C/C++test 已安装在计算机上，并且已知 `cpptestcli` 启动器的路径（例如， `/home/<user>/parasoft/cpptest/cpptestcli` ）。 有关安装和许可证激活说明，请参阅 [Parasoft C/C++test 安装指南](https://docs.parasoft.com/display/CPPTEST20261/Installation+Guide)。

* 项目中的 C/C++test 设置文件（例如 `cpptest.localsettings.properties` ），用于接受 EULA、提供许可证并列出报告格式设置。 要使用 SARIF 查看器，请在报告格式设置中包含 `sarif` ： ```PROPERTIES report.format=html,xml,sarif report.location=./reports ```

## 配置外部工具

为每个分析作用域定义一个外部工具，例如一个用于单文件分析，另一个用于项目级分析

Procedure:

1. 打开  `设置 | 工具 | 外部工具` 。

![外部工具设置](https://resources.jetbrains.com/help/img/idea/2026.3/cl_parasoft_external_tools.png)

2. 点击   Add  （  `+` ）。

3. 填写必填字段，然后点击   确定  。

![工具设置](https://resources.jetbrains.com/help/img/idea/2026.3/cl_parasoft_tool_example.png)

### 参数

以下是用于单文件分析的实参示例：

```PLAINTEXT
-settings
"$ProjectFileDir$/cpptest.localsettings.properties"
-compiler
gcc_13-aarch64
-config
"builtin://Modern C++ (11, 14 and 17)"
-input
$CMakeCurrentBuildDir$/compile_commands.json
-resource
$FilePath$

```

* `-settings` —— 含许可证与报告格式设置的本地配置文件。

* `-compiler` —— 匹配工具链的编译器配置 id。

* `-config` —— 测试配置。 可以使用内置配置，如图所示，也可以指向 `.properties` 文件，例如 `"$ProjectFileDir$/[rules].properties"` 。 上例中的内置配置是 Parasoft 为 Modern C++ 提供的内置配置。 如果许可证包含 MISRA C++ 2023 规则，例如配置为 `-config "builtin://MISRA C++ 2023"` 。

* `-input` —— 编译数据库，使 cpptestcli 能够获取用于构建每个文件的确切标志或包含项。

* `-resource` —— 限制只分析当前文件的作用域。 进行项目级别分析时不需要此实参，因为项目级别是 cpptestcli 的默认作用域。

> **Note:**
> 包含空格的实参，如名称带空格的配置文件路径，必须加引用。类似  `report.format`  的逗号分隔列表不能有空格（  `html,xml,sarif` ，而非  `html, xml, sarif` ）。

## 运行分析

要运行分析，请在主菜单中选择  `工具 | 外部工具 | <tool 名称>` 。

![运行分析](https://resources.jetbrains.com/help/img/idea/2026.3/cl_parasoft_run_tool.png)

启动器输出会显示在  `运行`  工具窗口中。

![分析输出](https://resources.jetbrains.com/help/img/idea/2026.3/report.sarif`  文件。 分析结果将在  `问题`  工具窗口的   SARIF 结果   标签页打开，按工具和规则分组。 每个结果会显示规则信息及其源代码位置。

![SARIF 结果窗口](https://resources.jetbrains.com/help/img/idea/2026.3/cl_parasoft_sarif_viewer.png)

要打开某个分析结果的代码，请按两次点击它，按下  `Enter` ，或从上下文菜单中选择   跳转到源  。

![跳转到源](https://resources.jetbrains.com/help/img/idea/2026.3/cl_parasoft_sarif_jump_to_source.png)

CLion 会记住已导入报告的路径，并在重新打开项目时自动加载。

有关详细信息，请参阅 [SARIF Viewer](sarif-viewer-report.html)。

