8

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
cpp_noob
  • 253
  • 2
  • 6
  • 12
  • 1
    Promise that the directory name there is spelled right and contains your code and objects? Have you tried running it in that directory as `lcov --directory .`? – Cascabel Jan 30 '11 at 17:30
  • I edited my question, You are right: my stupid "careless". But then, the new error message beat me too: geninfo: ERROR: /home/Projects/Game1/main.gcno: reached unexpected end of file – cpp_noob Jan 30 '11 at 17:44
  • 1
    I have the same error exactly, did you have any luck in the end? – PierreBdR Nov 14 '13 at 17:10
  • Do you have only one gcc version installed? I got the same problem when install g++4.7 to Ubuntu 12.04 and do it default, but when I checked gcov version, it was for 4.6. Real /usr/bin/gcov is just symlink to gcov-4.6, so I tryed to fix it to gcov-4.7, after that I got correct work gcov from bash, but the same error for lcov. My solution was use g++4.6 instead g++ (symlink to g++4.7) – aknew Dec 05 '13 at 12:29

3 Answers3

14

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.

6502
  • 112,025
  • 15
  • 165
  • 265
Blaise
  • 7,230
  • 6
  • 43
  • 53
2

I had exactly the same problem. And it turned out that if the library code changes while you had already ran the coverage tests, sometimes it gets confused. The only way to get out of it is to remove the file(s) causing the error and recompile.

PierreBdR
  • 42,120
  • 10
  • 46
  • 62
-5

Compile the code using :

lcov --directory . --output-file app.info

Then use the following to make the html pages.

genhtml app.info
martijnn2008
  • 3,552
  • 5
  • 30
  • 40
Aakash Anuj
  • 3,773
  • 7
  • 35
  • 47