You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Gcov中分别指定.gcno与.gcda文件的存储目录?

Correct Ways to Specify Separate .gcno and .gcda Paths in Gcov

First, let's fix the common mistake in your command: the -o option expects a directory (not a file path) where gcov can find the .gcno file. Your attempt to pass the full .gcno file path to -o was causing issues. Here are two reliable methods to handle separate .gcno and .gcda directories:

Method 1: Use --gcda-file (GCC 9+)

If you're using GCC 9 or newer, gcov supports the --gcda-file flag, which lets you explicitly specify the path to your .gcda file. This is the cleanest approach:

gcov -o data/gcno evenodd.c --gcda-file=data/gcda/evenodd.gcda
  • -o data/gcno: Tells gcov to look for evenodd.gcno in the data/gcno directory.
  • --gcda-file=data/gcda/evenodd.gcda: Directly points to the specific .gcda file for your test case.
  • evenodd.c: The source file you want to generate coverage reports for.

This will generate the coverage output files (like evenodd.c.gcov) in your current working directory, using the exact .gcno and .gcda files you specified.

Method 2: Temporary Directory (Older GCC Versions)

If you're stuck with an older GCC version that doesn't support --gcda-file, you can use a temporary directory to bring the .gcno and .gcda files together:

  1. Create a temporary directory for your test case:
    mkdir temp_evenodd
    
  2. Copy or symlink the .gcno and .gcda files into this directory:
    cp data/gcno/evenodd.gcno temp_evenodd/
    cp data/gcda/evenodd.gcda temp_evenodd/
    
  3. Run gcov with the temporary directory as the -o target:
    gcov -o temp_evenodd evenodd.c
    
  4. Clean up the temporary directory once you have your coverage reports:
    rm -r temp_evenodd
    

This works because gcov expects .gcno and .gcda files to be in the same directory when using -o.

Automating for Multiple Test Cases

Since you have multiple .gcda files (one per test case), you can wrap this logic in a script to avoid repetitive manual steps. For example, a bash script could loop through all .gcda files in data/gcda/, generate individual coverage reports, and store them in a dedicated output directory.

内容的提问来源于stack exchange,提问作者AceVez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:57:00