I am using ubuntu 10.1, g++ compiler.
I trying to use gcov and lcov for my C++ project. I manage to compile the gcov:
g++ -fprofile-arcs -ftest-coverage main.cpp user.cpp game.cpp
There is no error or warning message. Next I try to run gcov:
gcov main.cpp user.cpp game.cpp
Also fine. I also try to run my program:
./a.out
and run gcov again, my main, user and game.cpp shows some percentage now. I want to capture the data, I type this in terminal:
lcov --directory /home/projects/Game1/ -c -o application.info
But it gives me this:
Capturing coverage data from /home/projects/Game1/
geninfo: ERROR: cannot read /home/projects/Game1/!
I search all over the web, read lcov documentation, I cant find the answers. Anyone can help me?
In addition, I also could not open the main.gcda file.(I tried open using text editor, it says some character encoding problem, quite alot: UTF-8, Western (ISO-8859-1), Western (ISO-8859-11) etc, but still cant open and read the file.
Please help me.. anyone??
EDIT:
I admit, its my mistake (i am terribly sorry, "home/Projects/Game1" with capital "P".) After verifying the path, I got this new error:
geninfo: ERROR: /home/Projects/Game1/main.gcno: reached unexpected end of file
Be sure to include -g flag (debug information): -g -fprofile-arcs -ftest-coverage
While working with lcov I found that it is better to use absolute paths instead of relative paths. You can try to use lcov to capture initial zero coverage date with -i, --initial switch.
Here is an example of my way of achieving zerocounters
$ lcov --zerocounters --directory myFullPath
$ lcov --capture --initial --directory myFullPath --output-file myOutputFile
Then run your program and then capture the coverage data:
$ lcov --no-checksum --directory myFullPath --capture --output-file myOutputFile
Finaly lcov enables you to generate html report:
$ lcov/genhtml --highlight --legend --output-directory myOutPutHTMLdirectory myOutputFile
Hope this helps you.