macosgccgprof

Problem with gprof on OS X: [program] is not of the host architecture


I'm having trouble running gprof on OS X. The file test.c is:

#include <stdio.h>

int main() {
  printf("Hello, World!\n");
  return 0;
}

and my terminal looks like:

$ gcc -pg test.c
$ gcc -pg -o test test.c
$ ./test
Hello, World!
$ gprof test
gprof: file: test is not of the host architecture

Edit: also, it doesn't generate the file gmon.out.

What's going on here?


Solution

  • The series of events here is supposed to work as follows:

    1. Compile code with -pg option
    2. Link code with -pg option
    3. Run program
    4. Program generates gmon.out file
    5. Run gprof

    The problem is that step 4 never happens. There's very little information out about this specific failure. The general consensus over the past few years seems to be that Apple would rather use shark instead, and they've been very lax about fixing bugs and such with gprof.

    In short: Install Xcode, man shark