问题
Cppcheck scans all files in a project folder:
c:\projectfolder\main.c
c:\projectfolder\file.c
c:\projectfolder\file.h
c:\projectfolder\file_test.cc
c:\projectfolder\file_test.cc
contains the following code
#include "c:/gtest/gtest.h"
extern "C"
{
#include "TMyStruct.h"
}
TEST(Stack, Overflow)
{
TMyStruct unterTest;
EXPECT_EQ(1, TMyStruct_Init(&unterTest));
EXPECT_GE(unterTest.variable, 9000);
}
File file_test.cc
includes the gtest.h file
C:\gtest\gtest.h
All files in C:\gtest\ should not be tested.
I call
cppcheck.exe -ic:\gtest\ c:\projectfolder\ --enable=style --template="SomeError"
Errors are found and reported in c:\projectfolder\file_test.cc
coming from the included gtest.h
(detail: "too many #ifdef configurations").
How do I tell Cppcheck to not look at C:\gtest\gtest.h
at all?
回答1:
My project structure looks like this:
├── build
├── lib
│ └── dep
│ └── dep.h
├── src
│ ├── code.c
│ └── code.h
└── tests
└── code_test.c
To suppress warnings for lib
includes, I did this:
cppcheck --enable=all --suppress='*:lib/*' -Isrc -Itests ./src ./tests 1>/dev/null
Maybe this should work on Windows:
cppcheck.exe --suppress='*:c:\gtest\*' c:\projectfolder\
My Cppcheck version is 1.74.
Reference:
Allow ignoring results from header files
回答2:
I am a Cppcheck developer. I don't think you can skip a header file. Perhaps -i should work like that.
Feel free to create a ticket about this: http://sourceforge.net/apps/trac/cppcheck/
来源:https://stackoverflow.com/questions/13591696/how-can-i-tell-cppcheck-to-skip-a-header-file