我正在学习gcov生成覆盖率报告。这些守则如下:a.h
#include <stdio.h>
int A(int a);
交流
#include "a.h"
int A(int a)
{
int b = a * a * a * a;
return b;
}
c
#include <stdio.h>
#include "a.h"
int main()
{
int a1 = A(33);
printf("a1 = %dn", 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的任何内容。
这是一个有趣的问题,当我使用gcc a.h a.c main.c -o app -fprofile-arcs -ftest-coverage
,只是改变a.h和a.c之间的序列,它的工作。