【问题标题】:Configure coverity for ndk-build为 ndk-build 配置覆盖率
【发布时间】:2014-02-19 01:11:54
【问题描述】:

我想使用coverity 进行静态分析,而我需要它用于c++。由于我的项目使用的是Android NDK,所以我将编译器配置为:

cov-configure –comptype gcc –compiler ~/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc-4.6

然后我跑了cov-build –dir coverity ndk-build –j8 NDK_DEBUG=1

一切都在构建,但我有一个警告

*[*WARNING] No files were emitted. This may be due to a problem with your configuration
or because no files were actually compiled by your build command.
Please make sure you have configured the compilers actually used in the compilation.**

所以我忽略了警告并跑了

cov-analyze –dir coverity –all
**Coverity Static Analysis for C/C++ version 6.6.1 on Linux 2.6.38-8-server x86_64
Internal version numbers: d614fc01a4 p-eureka-push-15003.308

Looking for translation units
Error: no matching translation units.**

那么我的编译器配置正确吗?有没有人为 Android NDK 配置过编译器?

【问题讨论】:

    标签: gcc android-ndk coverity


    【解决方案1】:

    在coverity/build-log.txt 中,您应该看到构建期间执行的所有命令(查找“EXECUTING:”)。仔细检查编译器命令是否与您为 cov-configure 指定的编译器匹配。您可以配置多个编译器,配置通用 gcc(“cov-configure --gcc”)可能很有用。

    请记住,如果您的 ndk-build 实际上没有构建任何东西,那么 cov-build 将给出类似的消息。换句话说,该消息并不总是表明存在问题——有可能构建已完成,但实际上并未编译任何文件。

    【讨论】:

    • 您好,感谢您的回复。编译后它会在 libs 文件夹下生成 .so 文件。我看到编译器命令是正确的。编译器的路径也是正确的。您能否澄清当 ndk-build 不编译任何文件时是什么意思。再次感谢
    【解决方案2】:

    您应该为 NDK 配置正确的编译器:

    cov-configure --comptype gcc -compiler arm-linux-androideabi-gcc --template
    

    【讨论】:

    • 没错!编译器名称很重要。有关详细信息,请参阅 Coverity 文档!
    【解决方案3】:

    您表示编译器是 ~/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc -4.6

    确保这是命令中正确的完整路径(也许替换 '~'?),并且 arm-linux-androideabi-gcc-4.6 正是用于编译的路径。

    我遇到了同样的问题,因为 Coverity 期望使用 GCC,但我的构建使用了 cc!

    然后我设置:

    ~/coverity-current/bin/cov-configure --compiler /usr/bin/cc --comptype gcc
    

    它显示了:

    [WARNING] A template configuration is recommended for this compiler.
    Add "--template" to your command line, or use one of the
    template configuration shortcut command lines below:
    
      cov-configure --gcc      # GNU C/C++ compiler (gcc/g++)
      cov-configure --msvc     # Microsoft C/C++ compiler (cl)
      cov-configure --java     # Sun Java compiler (javac)
    
    You must remove the specific configuration before re-running with "--template".
    * Configuring /usr/bin/cc as a C compiler
    [WARNING] Config gcc-config-2 already exists for cc gcc gcc-4.8 as gcc and will be reused. 
    * Configuring /usr/bin/cc as a C++ compiler
    [WARNING] Config g++-config-2 already exists for cc gcc gcc-4.8 as g++ and will be reused. 
    
    Generated coverity_config.xml at location /home/default/cov-analysis-linux64-X.X.X/config/coverity_config.xml
    Successfully generated configuration for the compilers: cc gcc gcc-4.8
    

    cov-build 命令是:

    ../../coverity-current/bin/cov-build --dir ~/build_cov/myapp/cov-log-all-output make -C ~/build_cov/myapp
    

    结果:

    ../../coverity-current/bin/cov-build --dir ~/build_cov/myapp/cov-log-all-output make -C ~/build_cov/myapp
    
    [...]
    
    76 C/C++ compilation units (100%) are ready for analysis
    The cov-build utility completed successfully.
    

    cov-log-all-output/c/emit/pcname/ 中有一个更大的 emit-db 文件

    【讨论】:

      【解决方案4】:

      所以我只是遇到了同样的问题并解决了它。 在我的情况下,make 文件是问题所在,即使编译器配置正确,我也收到以下警告:

      没有发出任何文件。这可能是由于您的配置有问题 或者因为您的构建命令实际上没有编译任何文件。 请确保您已经配置了编译中实际使用的编译器。

      make 文件包含一些目标,而不是我打算使用的目标。所以如果您不确定 makefile 中定义的所有目标,只需删除它们并编译您需要并知道的任何目标。.else 与其他人讨论剩余目标。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-02-29
        • 2017-10-24
        • 2016-07-07
        • 1970-01-01
        • 1970-01-01
        • 2013-10-16
        • 2017-09-13
        相关资源
        最近更新 更多