LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   gcc -pg, but no gmon.out produced? (http://www.linuxquestions.org/questions/programming-9/gcc-pg-but-no-gmon-out-produced-772118/)

Some__Guy 11-28-2009 11:11 AM

gcc -pg, but no gmon.out produced?
 
Hi,

I'm having some trouble trying to profile my code. I'm just testing it out with a simple hello world program:

Code:

$ cat bar.c
#include <stdio.h>

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

However, when I compile and run it, no gmon.out is produced (as required by gprof):

Code:

$ gcc -o bar bar.c -pg && ./bar && ls ./gmon.out
Hello, world!
ls: ./gmon.out: No such file or directory

Is there anything obvious that I'm screwing up here? I'm running this on OS X 10.5.

Thanks.

khodeir 11-29-2009 07:48 AM

hmm try
Quote:

gcc bar.c -o bar.out
to compile the C file
and
Quote:

./bar.out
to run it

or try
Quote:

$ gcc -o bar bar.c -pg && ./bar && ls gmon.out
and tell me what happens

graemef 11-29-2009 10:25 AM

put your -pg switch before the input file
Code:

$ gcc -pg -o bar bar.c

Some__Guy 11-30-2009 01:14 AM

Quote:

Originally Posted by khodeir (Post 3773138)
hmm try

to compile the C file
and
to run it

or try

and tell me what happens

Code:

$ gcc -o bar bar.c -pg && ls gmon.out
Hello, world!
ls: gmon.out: No such file or directory

Quote:

Originally Posted by graemef (Post 3773280)
put your -pg switch before the input file
Code:

$ gcc -pg -o bar bar.c

Code:

$ gcc -pg -o bar bar.c && ls gmon.out
ls: gmon.out: No such file or directory

*confused*

graemef 11-30-2009 02:50 AM

Code:

gcc -Wall -pg -c bar.c
gcc -Wall -pg -o bar bar.o

Will compile and link you program, creating an executable with additional instructions that record the time spent in each function.
Code:

./bar
Will run the executable created above, with profiling data written to a file ‘gmon.out’ in the current directory
Now you can try:
Code:

ls -l
To see if the file has been created.

Some__Guy 11-30-2009 08:34 AM

Quote:

Originally Posted by graemef (Post 3774053)
Code:

gcc -Wall -pg -c bar.c
gcc -Wall -pg -o bar bar.o

Will compile and link you program, creating an executable with additional instructions that record the time spent in each function.
Code:

./bar
Will run the executable created above, with profiling data written to a file ‘gmon.out’ in the current directory
Now you can try:
Code:

ls -l
To see if the file has been created.

Code:

$ gcc -Wall -pg -c bar.c && gcc -Wall -pg -o bar bar.o && ./bar && ls -l
Hello, world!
total 48
-rwxr-xr-x  1 i_am_not_root  staff  13400 Nov 30 08:33 bar*
-rw-r--r--  1 i_am_not_root  staff    78 Nov 25 23:17 bar.c
-rw-r--r--  1 i_am_not_root  staff    556 Nov 30 08:33 bar.o

It sounds like this may be a bug with Leopard.

oldardy 06-25-2011 11:17 AM

gcc bar.c -pg -o bar
./bar
gprof bar

is my solution (works on kubuntu 11.04)

oldardy


All times are GMT -5. The time now is 01:00 PM.