【问题标题】:cannot find an entry for .cpp.gcov in .gcno file, skipping file在 .gcno 文件中找不到 .cpp.gcov 的条目,正在跳过文件
【发布时间】:2023-07-09 11:43:01
【问题描述】:
g++ (Ubuntu 9.4.0-1ubuntu1~18.04) 9.4.0
gcov (Ubuntu 9.4.0-1ubuntu1~18.04) 9.4.0
lcov: LCOV version 1.13
  1. g++ -g -O0 --coverage main.cpp -o main
  2. ./main
  3. lcov -t "main" -o main.info -c -d 。 --gcov-tool gcov-9

输出:

Capturing coverage data from .
Found gcov version: 9.4.0
Scanning . for .gcda files ...
Found 1 data files in .
Processing main.gcda
geninfo: WARNING: /home/home/main.gcno: Overlong record at end of file!
geninfo: WARNING: cannot find an entry for main.cpp.gcov in .gcno file, skipping file!
Finished .info-file creation
  1. genhtml -o 报告 main.info

输出:

genhtml: ERROR: no valid records found in tracefile main.info

【问题讨论】:

    标签: gcc gcov lcov


    【解决方案1】:

    到目前为止,我还没有设法使用 lcov。但我找到了适合我的解决方案。

    1. 安装gcovrhttps://github.com/gcovr/gcovr
    2. 使用-fprofile-arcs -ftest-coverage -g -O0 构建您的应用程序
    3. 将 gcov 链接到您的可执行文件/库 (-lgcov)
    4. 使用gcov-9 -b -l -p -c *.gcno 命令创建.gcov 文件。 (如果您使用的是 cmake,则需要通过所有 CMakeFiles/{all subfolders}.dir/src/* 目录递归地运行此命令)
    5. gcovr {rootDir} -r {sourceDir} -g -k --html --html-details -o tp.html

    rootDir - 您可以从中访问 .gcov 的目录。 sourceDir - 应在 tp.html 报告中的源