【问题标题】:Using gcov to generate a coverage for c sources, get a error 'not a gcov notes file'使用 gcov 为 c 源生成覆盖,得到错误“不是 gcov 注释文件”
【发布时间】:2021-10-17 20:00:03
【问题描述】:

我正在学习 gcov 以生成覆盖率报告。这些代码如下: 呵呵

#include <stdio.h>

int A(int a);

交流

#include "a.h"

int A(int a)
{
        int b = a * a * a * a;
        return b;
}

main.c

#include <stdio.h>
#include "a.h"

int main()
{
        int a1 = A(33);
        printf("a1 = %d\n", a1);
        return 1;
} 

我使用gcc *.c *.h -o main -fprofile-arcs -ftest-coverage编译代码, 那么当前目录中的文件是a.c a.gcno a.h main main.c main.gcno。 接下来,

root@DESKTOP-D0VRGT9:/home/liguoyang/coverage# lcov -d . --capture -o main.info
Capturing coverage data from .
Found gcov version: 9.3.0
Using intermediate gcov format
Scanning . for .gcda files ...
Found 2 data files in .
Processing a.gcda
/home/liguoyang/coverage/a.gcno:not a gcov notes file
/home/liguoyang/coverage/a.gcda:stamp mismatch with notes file
geninfo: WARNING: GCOV did not produce any data for /home/liguoyang/coverage/a.gcda
Processing main.gcda
Finished .info-file creation

这里出现错误

/home/liguoyang/coverage/a.gcno:not a gcov notes file
/home/liguoyang/coverage/a.gcda:stamp mismatch with notes file

root@DESKTOP-D0VRGT9:/home/liguoyang/coverage# genhtml -o result main.info
Reading data file main.info
Found 1 entries.
Found common filename prefix "/home/liguoyang"
Writing .css and .png files.
Generating output.
Processing file coverage/main.c
Writing directory view page.
Overall coverage rate:
  lines......: 100.0% (4 of 4 lines)
  functions..: 100.0% (1 of 1 function)

在生成html的时候,没有a.c.

【问题讨论】:

    标签: c code-coverage gcov


    【解决方案1】:

    这是一个有趣的问题,当我使用 gcc a.h a.c main.c -o app -fprofile-arcs -ftest-coverage 时,只需将 a.h 和 a.c 之间的顺序更改为有效。

    【讨论】:

      猜你喜欢
      • 2015-02-01
      • 1970-01-01
      • 2015-11-26
      • 2012-04-18
      • 2023-03-03
      • 2011-06-06
      • 2016-02-25
      • 2015-09-29
      相关资源
      最近更新 更多