我该如何告诉 lcov 去哪里找我的 .cpp 和 .h 文件?

12

我的源代码和构建目录如下(参见Makefile to put object files from source files different directories into a single, separate directory?),经过make编译和运行FooAndBarTests之后:

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选项。它会添加用于调试的元数据(包括文件路径和行号,我想)。 - sellibitze
我在编译时已经使用了-g选项。 - Daryl Spitzer
1个回答

17

使用 -b 选项来运行 lcov。该选项指定了代码库。


将“-b .”添加到我的lcov命令行(在我进行make的同一目录中运行)就解决了问题。 - Daryl Spitzer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接