cppcheck --enable=all -i ./samples --inconclusive --xml --xml-version=2 ./* 2> %WORKSPACE%/cppcheck.xml

--enable=all
默认情况下,只显示错误消息,可以通过--enable命令启用更多检测

--enable= Enable additional checks. The available ids are: * all Enable all checks. It is recommended to only use --enable=all when the whole program is scanned, because this enables unusedFunction. * warning Enable warning messages * style Enable all coding style checks. All messages with the severities 'style', 'performance' and 'portability' are enabled. * performance Enable performance messages * portability Enable portability messages * information Enable information messages * unusedFunction Check for unused functions. It is recommend to only enable this when the whole program is scanned. * missingInclude Warn if there are missing includes. For detailed information, use '--check-config'. Several ids can be given if you separate them with commas. See also --std

启用警告消息:

cppcheck --enable=warning file.c

启用性能消息:
命令参数错误什么意思_命令行参数错误_format命令参数错误

cppcheck --enable=performance file.c

启用信息消息:

cppcheck --enable=information file.c

因为历史缘由--enable=style可以启用警告、性能、可移植性和式样信息。当使用旧XML格式时,那些都由style表示:

cppcheck --enable=style file.c

启用警告和性能消息:

cppcheck --enable=warning,performance file.c

启用unusedFunction复查。这不能通过--enable=style启用,由于不会在库中正常工作。

cppcheck --enable=unusedFunction file.c

启用所有消息:

cppcheck --enable=all

-i
-i
提供一个源文件或源文件目录以排除从检测。这只适用于源文件源文件包含的头文件不匹配。目录名与路径的所有部份相匹配。
--inconclusive
--inconclusive
容许Cppcheck报告wps for linux,虽然剖析是不确定。这个选项有假阴性。每位结果在你晓得它是否存在之前,必须仔细调查好或坏。
不确定消息
默认情况下,假如确定,Cppcheck只显示错误消息。假如使用--inconclusive,当剖析不确定时,也会写错误消息。

cppcheck --inconclusive path

选择XML文件版本。目前只有版本2是可用的。
保存结果到文件中
好多时侯,会希望将结果保存在一个文件中,可以使用shell的管线重定向错误输出到一个文件:

cppcheck file.c 2> err.txt

多线程检测
选项-j用于指定须要使用的线程数,比如format命令参数错误format命令参数错误,使用4个线程检测文件夹中的文件:

cppcheck -j 4 path

XML输出
Cppcheck可以生成XML格式的输出。有一蒙自的XML格式(version1)和一个新的XML格式(version2)。假如可以,请使用新版本。
旧版本保持向后兼容性。它不会改变,但有三天可能会被删掉。使用--xml支持这些格式。
新版本修补一些旧格式的问题。新格式可能会在cppcheck的未来版本中更新linux运维博客,并带有新的属性和元素。用于检测文件并以新的XML格式输出错误的示例命令:

cppcheck --xml-version=2 file.cpp

-xml
--xml将结果以xml格式写入错误流(stderr)。
--xml-version
--xml-version=