LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 11-28-2009, 11:11 AM   #1
Some__Guy
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Rep: Reputation: 0
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.
 
Old 11-29-2009, 07:48 AM   #2
khodeir
Member
 
Registered: Feb 2009
Distribution: Debian
Posts: 243

Rep: Reputation: 33
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
 
Old 11-29-2009, 10:25 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
put your -pg switch before the input file
Code:
$ gcc -pg -o bar bar.c
 
Old 11-30-2009, 01:14 AM   #4
Some__Guy
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by khodeir View Post
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 View Post
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*
 
Old 11-30-2009, 02:50 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
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.

Last edited by graemef; 11-30-2009 at 02:53 AM. Reason: added -Wall
 
Old 11-30-2009, 08:34 AM   #6
Some__Guy
LQ Newbie
 
Registered: Nov 2009
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by graemef View Post
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.
 
Old 06-25-2011, 11:17 AM   #7
oldardy
LQ Newbie
 
Registered: Jun 2011
Posts: 1

Rep: Reputation: Disabled
gcc bar.c -pg -o bar
./bar
gprof bar

is my solution (works on kubuntu 11.04)

oldardy

Last edited by oldardy; 06-25-2011 at 11:20 AM. Reason: forgot profiling
 
  


Reply

Tags
gcc


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with gprof, no gmon.out file !! taj2000 Linux - Software 2 05-21-2009 10:01 PM
gmon.out not created while using gprof on target board VGM Linux - General 0 04-14-2009 02:55 AM
Observation of Assembly code produced by GCC 4.3.2 for various -march parameters Mr_Shameless Programming 1 10-25-2008 06:54 AM
gprof: gmon.out: not in a.out format hemk76 Programming 7 11-06-2005 11:05 AM
difference between distro produced by group vs. produced by single person lostsoul Linux - General 2 04-08-2004 02:29 PM


All times are GMT -5. The time now is 12:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration