Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how do i compile this simple program???

Reply
Thread Tools

how do i compile this simple program???

 
 
David
Guest
Posts: n/a
 
      08-27-2003
i am trying to compile the following with gcc on a RH 9.0 box:

#include <sys/types.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>

/* resource.c */

int main(int argc,char* argv[]){
struct rusage r_usage;
struct rlimit r_limit;
getrusage(RUSAGE_SELF, &r_usage);
printf("User: %ld.%06ld\n",r_usage.ru_utime.tv_sec,
r_usage.ru_utime.tv_usec);
getrlimit(RLIMIT_FSIZE,&r_limit);
printf("Current FSIZE limit: soft = %ld, hard = %ld\n",
r_limit.rlim_cur,r_limit.rlim_max);
return 0;
}

with:

gcc -o resource resource.c

but it came back with the error that says 'struct rusage r_usage' is
undeclared (it also complain about 'struct rlimit'). i am sure that i
have missed something so gcc is not able to find the definition of the
rusage strrct but since this is the first time i am trying to program
in linux, i don't know how to solve that. i have googled around for a
while with no avil. can someone tell me what's wrong? thanks!
 
Reply With Quote
 
 
 
 
Russell Hanneken
Guest
Posts: n/a
 
      08-27-2003
David wrote:
> i am trying to compile the following with gcc on a RH 9.0 box:
>
> #include <sys/types.h>
> #include <sys/resource.h>
> #include <sys/time.h>
> #include <unistd.h>
> #include <stdio.h>
>
> [ . . . ]
>
> but it came back with the error that says 'struct rusage r_usage' is
> undeclared (it also complain about 'struct rlimit').


David,

Since your problem isn't really C-language-related, you'll have better
luck asking this on a newsgroup that deals with Linux. See the welcome
message for this group:

http://www.angelfire.com/ms3/bchambl...me_to_clc.html

For what it's worth, I compiled your code without problems on my FreeBSD
machine and on some Linux machine (I don't know if it was Red Hat).

Regards,

Russell Hanneken
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      08-27-2003
David wrote:

> i am trying to compile the following with gcc on a RH 9.0 box:
>
> #include <sys/types.h>
> #include <sys/resource.h>
> #include <sys/time.h>
> #include <unistd.h>
> #include <stdio.h>
>
> /* resource.c */
>
> int main(int argc,char* argv[]){
> struct rusage r_usage;
> struct rlimit r_limit;
> getrusage(RUSAGE_SELF, &r_usage);
> printf("User: %ld.%06ld\n",r_usage.ru_utime.tv_sec,
> r_usage.ru_utime.tv_usec);
> getrlimit(RLIMIT_FSIZE,&r_limit);
> printf("Current FSIZE limit: soft = %ld, hard = %ld\n",
> r_limit.rlim_cur,r_limit.rlim_max);
> return 0;
> }
>
> with:
>
> gcc -o resource resource.c
>
> but it came back with the error that says 'struct rusage r_usage' is
> undeclared (it also complain about 'struct rlimit').


As you know, none of <sys/types.h>, <sys/resource.h>, <sys/time.h>, and
<unistd.h> are standard C, but are properties of your implementation & OS.
Not only does that make questions about the off-topic here, but may be
the key to your problem.

Apparently your installed version of gcc does not recognize the struct
definitions in <sys/resource.h>. This is what you expect when using -ansi
or -std=c89 or -std=c99 or their synonyms. Compiling your code with the
flags to specify the non-standard language -std=gnu89 or -std=gnu99 (I had
thought the default was -std=gnu89, but it seems otherwise for you), I find
those diagnostics disappear.

Even if that works (and check with a gcc newsgroup where it is topical),
you have an error in your code. In
> printf("User: %ld.%06ld\n",r_usage.ru_utime.tv_sec,
> r_usage.ru_utime.tv_usec);

r_usage.ru_utime.tv_sec should be a time_t, not a long. Simply casting it
with (long) should suffice. This would not normally be the way to do
things in comp.lang.c, since there is no reason to suppose that a time_t's
value will in general be representable in a long; however, your
non-standard application will -- for your particular and off-topic
implementation -- have no problem.



--
Martin Ambuhl

 
Reply With Quote
 
David
Guest
Posts: n/a
 
      08-27-2003
Russell Hanneken <(E-Mail Removed)> wrote in message news:<DTT2b.4780$(E-Mail Removed) link.net>...
> David wrote:
> > i am trying to compile the following with gcc on a RH 9.0 box:
> >
> > #include <sys/types.h>
> > #include <sys/resource.h>
> > #include <sys/time.h>
> > #include <unistd.h>
> > #include <stdio.h>
> >
> > [ . . . ]
> >
> > but it came back with the error that says 'struct rusage r_usage' is
> > undeclared (it also complain about 'struct rlimit').

>
> David,
>
> Since your problem isn't really C-language-related, you'll have better
> luck asking this on a newsgroup that deals with Linux. See the welcome
> message for this group:
>
> http://www.angelfire.com/ms3/bchambl...me_to_clc.html
>
> For what it's worth, I compiled your code without problems on my FreeBSD
> machine and on some Linux machine (I don't know if it was Red Hat).
>


sorry for the OT question and i thank everyone for the answer so far.
i will repost the questino to the right group.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
compile directive for conditional compile for Java 1.4 versus Java 5 timjowers Java 7 02-02-2011 12:08 AM
computation at compile time i.e. compile time functions usingtemplates Carter C++ 2 03-04-2009 06:43 PM
Compile versus not compile (VS 2005)?? stupid48@gmail.com ASP .Net 1 04-11-2008 08:24 PM
cant compile on linux system.cant compile on cant compile onlinux system. Nagaraj C++ 1 03-01-2007 11:18 AM



Advertisments