Ran to the same problem, g ++ 4.8.2 on CentOS 7. -pg
present both for compilation and for linking, started the process and exited normally, there is no gmon.out
.
I fixed this by replacing the call with _exit(status)
with exit(status)
. Note that the former is _exit (3), the system call, and the latter is the exit (2), the standard library method.
Why does it work? On the gprof
man page:
A profiled program should call exit (2) or return the profiling data normally, which should be saved in the gmon.out file.
Apparently, the gmon.out entry is output dependent (higher level) (2). So, make sure the code uses exit (2) (from stdlib), not _exit (3) (system call).
source share