c - 使用 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什么都没有
解决方案
这是一个有趣的问题,当我使用 时 gcc a.h a.c main.c -o app -fprofile-arcs -ftest-coverage
,只需更改 ah 和 ac 之间的顺序,就可以了。
推荐阅读
- java - LWJGL 3 : StackGet() 用法
- javascript - javascript 对象字段输入值 [object Object] 而不是字符串 Reactjs
- c# - 通过 Telegram API 客户端发送位置
- ios - 绑定和状态不会同时更新
- sql - Oracle SQL:从一组订单中仅选择包含某些类型的订单
- lua - Lua - “字符串到十六进制”和“十六进制到字符串”公式
- angular - Angular:从其他组件中的 HasChangesGuard 获取响应
- linux - Plasmacore.Datasource 通知数据引擎不工作 qml kde
- css - 删除蚂蚁设计图标中的白色外边框
- angular - 如何将 Apple Pay JS 与 Angular 集成