cppcheck 没有看到一些有错误的子文件夹:找不到或打开任何给定的路径

问题描述

运行 cppcheck

cppcheck.exe --enable=all --xml-version=2 2> out.xml folder\subfolder

对于某些子文件夹(5 个中的 3 个)出错

error: Could not find or open any of the paths given.

如果我重命名文件夹仍然是同样的错误。当我跑步时

 cppcheck.exe --enable=all --xml-version=2 2> out.xml folder

那些子文件夹也不会被检查,只检查了这个文件夹中的 2 个子文件夹。可能是什么问题?

更新:我没有注意到 beore,但似乎没有看到文件夹 cppcheck 只包含 .h/.hpp 文件,没有 .cpp 更新: 我确实可以检查该子文件夹中的确切文件

cppcheck.exe --enable=all --xml-version=2 2> out.xml folder\subfolder\file.cpp

奇怪..

如果我导航到该子文件夹并从那里运行 cppcheck 如果我没有指定确切的文件,我仍然会遇到同样的错误:找不到或打开任何给定的路径。

UPD2:之前没注意到,cppcheck 看不到的文件夹只包含头文件

解决方法

每当我使用 CPPCheck 时,我都会使用 PowerShell 脚本来解析每个文件夹和子文件夹。通常我会使用这些参数把它放在一个数组中:

$LIST_OF_CPP_FILES = @(Get-ChildItem -Path .\ -Filter *.cpp -Recurse -File -Name) # The recurse is what goes through each sub folder and finds files with extension .cpp
$LIST_OF_C_FILES = ... *.c ...
$LIST_OF_H_FILES = ... *.h ...

然后循环遍历现在保存相关文件的每个数组。

foreach($FILE in $LIST_OF_CPP_FILES)
{
  &'C:\Program Files\Cppcheck\cppcheck.exe' -q --inline-suppr $FILE --force #Look at CPPCheck documentation for info on these paramters
}

当然,将其保存在 PWD 中的 .ps1 文件中,然后使用命令提示符运行它。

./CPPCheckScript.ps1

如果您想将其写入 txt 或 xml 文件,您也可以这样做,或者只是在终端中打印输出。您也可以在 PowerShell 文件中使用 Write-Host