nukeguy
nukeguy

Reputation: 416

gmon.out isn't created when I compile with -pg flag with g++

I'm running on Mac OSX, version 10.8.5 (Mountain Lion). I have the following simple C++ code.

main.cpp:

#include <iostream>

int main ()
{
    std::cout << "Hello world!"<<std::endl;
    std::cout << "Goodbye world!"<<std::endl;
    return 0;
}

I'm trying to get gprof to work on my computer. As the manual suggests, I enter the following two lines into my terminal:

g++ -g -pg main.cpp -o a.out 
./a.out

However this does not generate a gmon.out file as it is supposed to. When I try typing gprof in the terminal, it says:

gprof: can't open: gmon.out (No such file or directory)

which is to be expected since gmon.out isn't there...

Any ideas on what I'm doing wrong?

EDIT: Some other things that may help:

Upvotes: 14

Views: 7910

Answers (1)

Steven Lu
Steven Lu

Reputation: 43417

You have to realize that OS X/MacOS does not provide GNU GCC on the system by default.

Note the output of this command:

ls -la /usr/bin/g++ /usr/bin/clang++

These executables look identical. (Actually! It looks like they are different, but somehow the filesize is identical!)

As far as I can tell, clang doesn't support the production of gprof output. As confusing as it may be, the gcc program will run clang.

I would recommend trying to use homebrew to install GCC on OS X/MacOS. You do want to be careful about how it gets installed, etc., so that you know which command corresponds to which compiler.

Upvotes: 2

Related Questions