macos gcov:无法打开图形文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6816839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:13:50  来源:igfitidea点击:

gcov: cannot open graph file

cmacosgcov

提问by Caleb Poucher

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

我正在尝试使用 gcov。我有这个简单的文件 ac:

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.

难道我做错了什么?我在 Mac OS X Lion 下。

回答by Steve Atkins

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

在 Lion 上,默认情况下,“gcc”不是 gcc。这是 LLVM。并且它不支持生成测试覆盖率数据。

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

如果你运行gcc-4.2 -fprofile-arcs -ftest-coverage a.c -o a,那将使用真正的 gcc,它可能会工作。

回答by Ben Hocking

Try using clanginstead of gcc. I had the same problem, and using clangfixed it for me.

尝试使用clang而不是gcc. 我遇到了同样的问题,并clang为我修复了它。

回答by nmat

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:

您确定从与源文件相同的目录运行命令吗?您必须在同一目录中,除非您指定 -o 标志。尝试:

gcov -o a.c

回答by zbeekman

Often this happens when the version of gcovyou're running doesn't match the version of GCC used to compile the application. On some systems, package managers have odd practices in how they link GCC and gcov. For example on many systems gfortranis the same as gfortran-5but gcovmight be something old and crusty.

gcov您运行的版本与用于编译应用程序的 GCC 版本不匹配时,通常会发生这种情况。在某些系统上,包管理器在如何链接 GCC 和gcov. 例如,在许多系统上gfortran是相同的,gfortran-5gcov可能是旧的和硬皮的。

回答by 0x90

I used the following on Mac 10.8.4:

我使用了以下内容Mac 10.8.4

  • Installed via xcode the command line tools:
  • 通过 xcode 安装命令行工具:

enter image description here

在此处输入图片说明

  • wrote this examplecode from the gcc website:

    #include <stdio.h>  
    main() 
    {  
       int i, total; total = 0; 
       for (i = 0; i < 10; i++) 
          total += i; 
       if (total != 45) 
          printf ("Failure\n"); 
       else 
          printf ("Success\n"); 
    }
    
  • Compiling using the real GCC gcc-mp-4.7 -fprofile-arcs -ftest-coverage tmp.c

  • And using GCC's gcov: gcov-mp-4.7 -b tmp.cwill give you this output:

    File 'tmp.c'
    Lines executed:87.50% of 8
    Branches executed:100.00% of 4
    Taken at least once:75.00% of 4
    Calls executed:50.00% of 2
    Creating 'tmp.c.gcov'
    
  • 从 gcc 网站写了这个示例代码:

    #include <stdio.h>  
    main() 
    {  
       int i, total; total = 0; 
       for (i = 0; i < 10; i++) 
          total += i; 
       if (total != 45) 
          printf ("Failure\n"); 
       else 
          printf ("Success\n"); 
    }
    
  • 使用真正的 GCC 编译 gcc-mp-4.7 -fprofile-arcs -ftest-coverage tmp.c

  • 并使用 GCC 的 gcov:gcov-mp-4.7 -b tmp.c会给你这个输出:

    File 'tmp.c'
    Lines executed:87.50% of 8
    Branches executed:100.00% of 4
    Taken at least once:75.00% of 4
    Calls executed:50.00% of 2
    Creating 'tmp.c.gcov'