cppcheck命令行参数说明

汉字均为翻译 以下翻译均采用谷歌翻译

Syntax: 语法

    cppcheck [OPTIONS] [files or paths]


If a directory is given instead of a filename, *.cpp, *.cxx, *.cc, *.c++, *.c,
*.tpp, and *.txx files are checked recursively from the given directory.
如果给出目录而不是文件名* .cpp,*。cxx,* .cc,* .c ++,* .c,
* .tpp和* .txx文件从给定目录递归检查。

Options:
    --cppcheck-build-dir=<dir>
                         Analysis output directory. Useful for various data.
                         Some possible usages are; whole program analysis,

                         incremental analysis, distributed analysis.

分析输出目录。 有用的各种数据。
                          一些可能的用法是: 整个程序分析,
                          增量分析,分布式分析。

    --check-config       Check cppcheck configuration. The normal code

                         analysis is disabled by this flag.

检查cppcheck配置。 正常代码
                          分析由此标志禁用

    --check-library      Show information messages when library files have

                         incomplete info.

库文件具有时显示信息消息
                          不完整的信息。

    --config-exclude=<dir>
                         Path (prefix) to be excluded from configuration
                         checking. Preprocessor configurations defined in
                         headers (but not sources) matching the prefix will not

                         be considered for evaluation.

要从配置中排除的路径(前缀)
                          检查。 在中定义的预处理器配置
                          匹配前缀的头(但不是源)不会
                          被考虑进行评价。

    --config-excludes-file=<file>

                         A file that contains a list of config-excludes

包含配置排除的列表的文件

    --dump               Dump xml data for each translation unit. The dump
                         files have the extension .dump and contain ast,

                         tokenlist, symboldatabase, valueflow.

转储每个翻译单元的xml数据。 转储
                          文件具有扩展名.dump并包含ast,
                          tokenlist,symboldatabase,valueflow。

    -D<ID>               Define preprocessor symbol. Unless --max-configs or
                         --force is used, Cppcheck will only check the given
                         configuration when -D is used.

                         Example: '-DDEBUG=1 -D__cplusplus'.

定义预处理器符号。 除非--max-configs或
                          --force被使用,Cppcheck只会检查给定
                          配置时使用-D。
                          示例:'-DDEBUG = 1 -D__cplusplus'。

    -U<ID>               Undefine preprocessor symbol. Use -U to explicitly
                         hide certain #ifdef <ID> code paths from checking.

                         Example: '-UDEBUG'

未定义预处理器符号。 使用-U显式
                          从检查中隐藏某些#ifdef <ID>代码路径。
                          示例:'-UDEBUG'

    -E                   Print preprocessor output on stdout and don't do any

                         further processing.

在stdout上打印预处理器输出,不做任何操作
                          进一步处理。

    --enable=<id>        Enable additional checks. The available ids are:

启用其他检查。 可用的ID是:

                          * all
                                  Enable all checks. It is recommended to only
                                  use --enable=all when the whole program is

                                  scanned, because this enables unusedFunction.

启用所有检查。 建议只有
                                   使用--enable = all当整个程序是
                                   扫描,因为这启用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

如果有缺失包括警告。 对于
                                   详细信息,请使用“--check-config”。
                          如果您将它们分开,可以给出几个ids
                          逗号。 另请参见--std

    --error-exitcode=<n> If errors are found, integer [n] is returned instead of
                         the default '0'. '1' is returned
                         if arguments are not valid or if no input files are
                         provided. Note that your operating system can modify

                         this value, e.g. '256' can become '0'.

如果发现错误,则返回integer [n],而不是返回
                          默认为'0'。 返回'1'
                          如果参数无效或没有输入文件
                          提供。 注意,您的操作系统可以修改
                          这个值,例如。 '256'可以变为'0'。

    --errorlist          Print a list of all the error messages in XML format.

以XML格式打印所有错误消息的列表。

    --doc                Print a list of all available checks.

打印所有可用检查的列表。

    --exitcode-suppressions=<file>
                         Used when certain messages should be displayed but

                         should not cause a non-zero exitcode.

在应显示某些消息时使用
                          不应该导致非零退出代码。

    --file-list=<file>   Specify the files to check in a text file. Add one
                         filename per line. When file is '-,' the file list will

                         be read from standard input.

指定要在文本文件中检查的文件。 添加一个
                          filename每行。 当文件是 - 时,文件列表将
                          从标准输入读取。

    -f, --force          Force checking of all configurations in files. If used
                         together with '--max-configs=', the last option is the

                         one that is effective.

强制检查文件中的所有配置。 如果使用
                          加上'--max-configs =',最后一个选项是
                          一个是有效的。

    -h, --help           Print this help.
    -I <dir>             Give path to search for include files. Give several -I
                         parameters to give several paths. First given path is
                         searched for contained header files first. If paths are

                         relative to source files, this is not needed.

指定搜索包含文件的路径。 给几个-I
                          参数给出几个路径。 首先给定的路径是
                          首先搜索包含的头文件。 如果路径
                          相对于源文件,这不是必需的。

    --includes-file=<file>
                         Specify directory paths to search for included header
                         files in a text file. Add one include path per line.
                         First given path is searched for contained header
                         files first. If paths are relative to source files,

                         this is not needed.

指定搜索包含的标题的目录路径
                          文件在文本文件中。 每行添加一个包含路径。
                          首先给定的路径搜索包含的头
                          文件。 如果路径相对于源文件,
                          这不是必需的。

    --include=<file>
                         Force inclusion of a file before the checked file. Can
                         be used for example when checking the Linux kernel,
                         where autoconf.h needs to be included for every file
                         compiled. Works the same way as the GCC -include

                         option.

强制在选中文件之前包含文件。 能够
                          例如在检查Linux内核时,
                          其中每个文件都需要包含autoconf.h
                          编译。 工作方式与GCC相同 - 包括
                          选项。

    -i <dir or file>     Give a source file or source file directory to exclude
                         from the check. This applies only to source files so
                         header files included by source files are not matched.

                         Directory name is matched to all parts of the path.

给出要排除的源文件或源文件目录
                          从检查。 这仅适用于源文件等
                          源文件包括的头文件不匹配。
                          目录名称与路径的所有部分匹配。

    --inconclusive       Allow that Cppcheck reports even though the analysis is
                         inconclusive.
                         There are false positives with this option. Each result
                         must be carefully investigated before you know if it is

                         good or bad.

即使分析是,仍允许Cppcheck报告
                          不确定。
                          这个选项有假阳性。 每个结果
                          必须仔细调查,才知道是否
                          是好是坏。

    --inline-suppr       Enable inline suppressions. Use them by placing one or
                         more comments, like: '// cppcheck-suppress warningId'

                         on the lines before the warning to suppress.

启用内联抑制。 通过放置一个或使用它们
                          更多评论,如:'// cppcheck-suppress warningId'
                          在线前警告压制。

    -j <jobs>            Start <jobs> threads to do the checking simultaneously.

启动<jobs>线程以同时进行检查。

    --language=<language>, -x <language>
                         Forces cppcheck to check all files as the given

                         language. Valid values are: c, c++

强制cppcheck检查所有文件作为给定
                          语言。 有效值为:c,c ++

    --library=<cfg>      Load file <cfg> that contains information about types
                         and functions. With such information Cppcheck
                         understands your your code better and therefore you
                         get better results. The std.cfg file that is
                         distributed with Cppcheck is loaded automatically.
                         For more information about library files, read the

                         manual.

加载包含类型信息的文件<cfg>
                          和功能。 有这样的信息Cppcheck
                          理解你的代码更好,因此你
                          获得更好的效果。 std.cfg文件是
                          分发与Cppcheck自动加载。
                          有关库文件的详细信息,请阅读
                          手册。

    --project=<file>     Run Cppcheck on project. The <file> can be a Visual
                         Studio Solution (*.sln), Visual Studio Project
                         (*.vcxproj), or compile database
                         (compile_commands.json). The files to analyse,
                         include paths, defines, platform and undefines in

                         the specified file will be used.

在项目上运行Cppcheck。 <file>可以是Visual
                          Studio解决方案(* .sln),Visual Studio项目
                          (* .vcxproj),或编译数据库
                          (compile_commands.json)。 要分析的文件,
                          包括路径,定义,平台和未定义
                          将使用指定的文件。

    --max-configs=<limit>
                         Maximum number of configurations to check in a file
                         before skipping it. Default is '12'. If used together
                         with '--force', the last option is the one that is

                         effective.

要在文件中检查的最大配置数
                          跳过它之前。 默认值为“12”。 如果一起使用
                          与“--force”,最后一个选项是一个
                          有效。

    --platform=<type>, --platform=<file>
                         Specifies platform specific types and sizes. The
                         available builtin platforms are:
                          * unix32
                                 32 bit unix variant
                          * unix64
                                 64 bit unix variant
                          * win32A
                                 32 bit Windows ASCII character encoding
                          * win32W
                                 32 bit Windows UNICODE character encoding
                          * win64
                                 64 bit Windows
                          * native
                                 Unspecified platform. Type sizes of host system

                                 are assumed, but no further assumptions.

指定平台特定类型和大小。 的
                          可用的内置平台有:
                           * unix32
                                  32位unix变体
                           * unix64
                                  64位unix变体
                           * win32A
                                  32位Windows ASCII字符编码
                           * win32W
                                  32位Windows UNICODE字符编码
                           * win64
                                  64位Windows
                           *本机
                                  未指定的平台。 键入主机系统的大小
                                  假设,但没有进一步的假设。

    -q, --quiet          Do not show progress reports.

不显示进度报告。

    -rp, --relative-paths
    -rp=<paths>, --relative-paths=<paths>
                         Use relative paths in output. When given, <paths> are
                         used as base. You can separate multiple paths by ';'.
                         Otherwise path where source files are searched is used.
                         We use string comparison to create relative paths, so
                         using e.g. ~ for home folder does not work. It is
                         currently only possible to apply the base paths to

                         files that are on a lower level in the directory tree.

在输出中使用相对路径。 当给定时,<路径>是
                          用作基础。 您可以通过';'分隔多个路径。
                          否则使用搜索源文件的路径。
                          我们使用字符串比较创建相对路径,所以
                          使用。 〜为home文件夹不工作。 它是
                          目前只能应用基本路径
                          目录树中较低级别的文件。

    --report-progress    Report progress messages while checking a file.

检查文件时报告进度消息。

    --rule=<rule>        Match regular expression.

匹配正则表达式。

    --rule-file=<file>   Use given rule file. For more information, see:

                         http://sourceforge.net/projects/cppcheck/files/Articles/

使用给定的规则文件。 有关详细信息,请参阅:
                          http://sourceforge.net/projects/cppcheck/files/Articles/

    --std=<id>           Set standard.
                         The available options are:
                          * posix
                                 POSIX compatible code
                          * c89
                                 C code is C89 compatible
                          * c99
                                 C code is C99 compatible
                          * c11
                                 C code is C11 compatible (default)
                          * c++03
                                 C++ code is C++03 compatible
                          * c++11
                                 C++ code is C++11 compatible (default)
                         More than one --std can be used:

                           'cppcheck --std=c99 --std=posix file.c'

设置标准。
                          可用的选项有:
                           * posix
                                  POSIX兼容代码
                           * c89
                                  C代码与C89兼容
                           * c99
                                  C代码与C99兼容
                           * c11
                                  C代码是C11兼容(默认)
                           * c ++ 03
                                  C ++代码与C ++ 03兼容
                           * c ++ 11
                                  C ++代码是C ++ 11兼容(默认)
                          可以使用多个--std:
                            'cppcheck --std = c99 --std = posix file.c'

    --suppress=<spec>    Suppress warnings that match <spec>. The format of
                         <spec> is:
                         [error id]:[filename]:[line]
                         The [filename] and [line] are optional. If [error id]

                         is a wildcard '*', all error ids match.

禁止符合<spec>的警告。 格式为
                          <spec>是:
                          [error id]:[filename]:[line]
                          [filename]和[line]是可选的。 如果[错误id]
                          是通配符“*”,所有错误ID都匹配。

    --suppressions-list=<file>
                         Suppress warnings listed in the file. Each suppression

                         is in the same format as <spec> above.

抑制文件中列出的警告。 每次抑制
                          与上述<spec>格式相同。

    --template='<text>'  Format the error messages. E.g.
                         '{file}:{line},{severity},{id},{message}' or
                         '{file}({line}):({severity}) {message}' or
                         '{callstack} {message}'

                         Pre-defined templates: gcc, vs, edit.

格式化错误消息。 例如。
                          '{file}:{line},{severity},{id},{message}'或
                          '{file}({line}):({severity}){message}'或
                          '{callstack} {message}'
                          预定义模板:gcc,vs,编辑。

    -v, --verbose        Output more detailed error information.

输出更详细的错误信息。

    --version            Print out version number.

    --xml                Write results in xml format to error stream (stderr).

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

    --xml-version=<version>
                         Select the XML file version. Currently versions 1 and

                         2 are available. The default version is 1.

选择XML文件版本。 目前版本1和
                          2可用。 默认版本为1。

Example usage:
  # Recursively check the current folder. Print the progress on the screen and
  # write errors to a file:
  cppcheck . 2> err.txt


  # Recursively check ../myproject/ and don't print progress:
  cppcheck --quiet ../myproject/


  # Check test.cpp, enable all checks:
  cppcheck --enable=all --inconclusive --std=posix test.cpp


  # Check f.cpp and search include files from inc1/ and inc2/:
  cppcheck -I inc1/ -I inc2/ f.cpp


For more information:
    http://cppcheck.net/manual.pdf
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在C++中使用Boost库进行命令行参数解析,您需要使用Boost.Program_options模块。以下是一个示例: ```cpp #include <iostream> #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int argc, char** argv) { po::options_description desc("Allowed options"); desc.add_options() ("help", "显示帮助信息") ("input", po::value<std::string>(), "输入文件名") ("output", po::value<std::string>(), "输出文件名"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << std::endl; return 0; } if (vm.count("input")) { std::string inputFileName = vm["input"].as<std::string>(); std::cout << "输入文件名: " << inputFileName << std::endl; } if (vm.count("output")) { std::string outputFileName = vm["output"].as<std::string>(); std::cout << "输出文件名: " << outputFileName << std::endl; } return 0; } ``` 在这个示例中,我们使用`boost::program_options`命名空间来定义命令行选项。`desc`对象包含了可以接受的选项,比如`--help`、`--input`和`--output`。每个选项都可以接受一个参数。 然后,我们使用`po::parse_command_line`函数来解析命令行参数,并将解析结果存储在`vm`(variables_map)对象中。`po::notify`函数用于通知`variables_map`对象已经完成解析。 接下来,我们可以通过检查`variables_map`对象中的选项是否存在来处理用户提供的命令行参数。在示例中,我们检查`--help`、`--input`和`--output`选项是否存在,并使用`as<std::string>()`方法获取选项的值。 如果用户提供了`--help`选项,我们将打印出命令行选项的帮助信息。否则,我们将打印出输入文件名和输出文件名(如果有提供的话)。 请确保在编译时链接了Boost.Program_options库,并将编译器的标志设置为`-lboost_program_options`。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值