Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcov: cannot open graph file

Tags:

c

macos

gcov

I am trying to use gcov. I have this simple file a.c:

int main() {
   return 0;
}

So I do

gcc -fprofile-arcs -ftest-coverage a.c -o a
./a
gcov a.c

and I get

a.gcno:cannot open graph file

Am I doing something wrong? I'm under Mac OS X Lion.

like image 260
Caleb Poucher Avatar asked Jul 25 '11 13:07

Caleb Poucher


3 Answers

By default on Lion, "gcc" is not gcc. It's LLVM. And it doesn't support generating test coverage data.

If you run gcc-4.2 -fprofile-arcs -ftest-coverage a.c -o a instead that will use a real gcc, and it'll probably work.

like image 172
Steve Atkins Avatar answered Nov 08 '22 10:11

Steve Atkins


Are you sure you are running the command from the same directory as the source file? You must be in the same directory, unless you specify the -o flag. Try:

gcov -o a.c
like image 25
nmat Avatar answered Nov 08 '22 12:11

nmat


Try using clang instead of gcc. I had the same problem, and using clang fixed it for me.

like image 2
Ben Hocking Avatar answered Nov 08 '22 10:11

Ben Hocking