如何告诉lcov在哪里可以找到我的.cpp&.h文件?

问题描述:

我的源和构建树是这个样子(见Makefile to put object files from source files different directories into a single, separate directory?)一个make(其中构建并运行FooAndBarTests)后:如何告诉lcov在哪里可以找到我的.cpp&.h文件?

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文件是?

+0

我不确定,但在编译时尝试使用-g选项。它为调试目的添加元数据(包括文件路径和行号,我认为)。 – sellibitze 2010-12-10 21:34:44

+0

编译时我已经使用了-g选项。 – 2010-12-11 00:11:27

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

+0

添加“-b”。到我的lcov命令行(当运行在我制作的同一个目录中)时,这个技巧就是了。 – 2010-12-23 20:58:25