【问题标题】:How do I tell lcov where to find my .cpp & .h files?如何告诉 lcov 在哪里可以找到我的 .cpp 和 .h 文件?
【发布时间】:2011-05-23 16:47:04
【问题描述】:

在 make(构建和运行 FooAndBarTests)之后,我的源代码和构建树看起来像这样(参见 Makefile to put object files from source files different directories into a single, separate directory?):

src
- Foo.cpp
- Bar.cpp
inc
- Foo.h
- Bar.h
test
- FooTest.cpp
- BarTest.cpp
- Main.cpp
- Makefile
- obj
  - Foo.gcda
  - Foo.gcno
  - Bar.gcda
  - Bar.gcno
- FooAndBarTests
UnitTest++
- libUnitTest++.a
- src
  - ...

然后我可以通过运行 gcov -o obj/ ../src/Foo.cppgcov -o obj/ ../src/Bar.cpp 在测试目录中生成 .gcov 文件。

但如果我运行 lcov -d obj/ -c -o FooAndBarTests.lcov 我会得到:

Capturing coverage data from obj/
Found gcov version: 4.2.1
Scanning obj/ for .gcda files ...
Found 4 data files in obj/
Processing Foo.gcda
../src/Foo.cpp:cannot open source file
Processing FooTest.gcda
FooTest.cpp:cannot open source file
../inc/Foo.h:cannot open source file
../UnitTest++/src/Checks.h:cannot open source file
...

然后当我运行genhtml FooAndBarTests.lcov 时,我得到:

Reading data file FooAndBarTests.lcov
Found 45 entries.
Found common filename prefix "/Users/dspitzer/FooAndBar/test"
Writing .css and .png files.
Generating output.
Processing file UnitTest++/src/Checks.h
genhtml: ERROR: cannot open /Users/dspitzer/FooAndBar/test/UnitTest++/src/Checks.h for reading!

如何告诉 lcov 和 genhtml .cpp 和 .h 文件在哪里?

【问题讨论】:

  • 我不确定,但在编译时尝试使用 -g 选项。它为调试目的添加了元数据(我认为包括文件路径和行号)。
  • 我在编译的时候已经在使用-g选项了。

标签: c++ code-coverage gcov lcov unittest++


【解决方案1】:

lcov 使用-b 选项。 -b 选项指定代码库。

【讨论】:

  • 添加“-b”。到我的 lcov 命令行(在我进行 make 的同一目录中运行时)成功了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-31
  • 1970-01-01
  • 2015-07-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多