0

Running cppcheck as

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

And for some subfolders(3 out of 5) got error

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

If I rename the folder still same error. And when I run

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

Those subfolders aren't checked as well, only 2 subfolders form this folder are checked. What could be the problem?

UPDATE: I haven't noticed that beore, but it seems that folders cppcheck don't see contains only .h/.hpp files, no .cpp UPD: I do can check exact file from that subfolder

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

Strange..

If I navigate to that subfolder and run cppcheck from there if I didn't specify exact file I still got same error: could not find or open any of the paths given.

UPD2: I haven't noticed it before, folders cppcheck don't see contains only header files

Name
  • 37
  • 4
  • from what I know the executable will only parse through the directory you specify, so it must be called multiple times. You can do this in a loop through a bash script – NeonFire Jul 15 '21 at 23:49
  • @NeonFire it goes through 2 subfolders, but for some reason don't see other 3. – Name Jul 15 '21 at 23:51
  • what does your file structure look like? – NeonFire Jul 15 '21 at 23:55
  • I would use the script I mentioned below becuase it's an easy terminal command and you can just drag a copy of the file in your root working directory each time you need it. – NeonFire Jul 15 '21 at 23:55
  • @NeonFire in some subfolders other subfolders with files (cpp and hpp), in some files and subfolder with files. Those two with whom cppcheck is ok one contain only cpp file, other contain other subfolders with files and cppcheck see them all – Name Jul 15 '21 at 23:59
  • maybe CPPCheck has a certain limit on how many subfolders deep it can search? – NeonFire Jul 16 '21 at 00:05
  • @NeonFire it doesn't explain why it cant see those folders when I navigate to them and try to run cppchech from there – Name Jul 16 '21 at 08:59
  • @NeonFire oh, I haven't noticed it before, folders cppcheck don't see contains only header files – Name Jul 16 '21 at 09:10

1 Answers1

0

Whenever I use CPPCheck, I use a PowerShell script to parse through each folder and sub-folder(s). Usually I would put it in an array using these parameters:

$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 ...

Then loop through each array which now holds the files in question.

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
}

Of course save this in a .ps1 file in your PWD and use Command Prompt to run it.

./CPPCheckScript.ps1

If you want to write it to a txt or xml file you can do that as well, or just have it print output in the terminal. You can use Write-Host in the PowerShell file as well.

NeonFire
  • 186
  • 2
  • 7