首页 > 解决方案 > 使用 gcov 为 c 源生成覆盖,得到一个错误 'not a gcov notes file'

问题描述

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

#include <stdio.h>

int A(int a);

交流

#include "a.h"

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

主程序

#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的时候,ac什么都没有

标签: ccode-coveragegcov

解决方案


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


推荐阅读