473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

how do i compile this simple program???

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!
Nov 13 '05 #1
3 3250
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
rh*******@pobox.com

Nov 13 '05 #2
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

Nov 13 '05 #3
Russell Hanneken <rh*******@pobox.com> wrote in message news:<DT*****************@newsread4.news.pas.earth 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.
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: john a. bailo | last post by:
I have created the world's greatest OSS program. Here it is. I defy you to compile and run it. This will separate the trolls from the zealots. HHAHAHAHAHHAAHAHHAH!!!!!
17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
22
by: Qopit | last post by:
Hi there, I'm pretty new to Python and am trying to figure out how to get "will this code compile?"-like code checking. To me this is a pretty basic language/environment requirement, especially...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
10
by: Bart Goeman | last post by:
Hi, I have a question about how to put redundant information in data structures, initialized at compile time. This is often necessary for performance reasons and can't be done at run time (data...
3
by: | last post by:
I am trying to compile a simple c# class in Web Matrix called howdy.cs: // Program start class public class HowdyPartner { // Main begins program execution public static void Main() { //...
109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
1
by: HugoScripts | last post by:
hi there, as i said i'm trying to compile a simple program that uses allegro, it's a small thing, indeed my goal was just to start using allegro, but until now i'm unable even to compile my simple...
3
by: Tom Baxter | last post by:
I just set up VS 2008 B2 and did a simple command line compile from the VS command prompt. I received this warning: warning CS1668: Invalid search path 'C:\Program Files\Microsoft...
4
by: Billy | last post by:
Hi! I'm using: -Compiler: Borland Command Line C++ Compiler 5.5.1 -Code Editor: SciTE 1.75 Anybody know how we can in Scite with command Tools|Go (F5) compile and run my c or cpp program at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.