Ubuntu rusage error

458 views Asked by At

I'm porting over some really old (and massive base of) code from CentOS 6 to Ubuntu 14.04. Note, I've installed the expected older version of gcc, fixed linker references, etc.

My build attempt is progressing, but I'm stuck on one thing. There's a C file that's trying to create a struct of type rusage, but the Ubuntu environment is giving me the following error: error: storage size of 'rusage' isn't known

As far as I can tell, all my paths look correct. I've even looked in the time.h and resource.h system files on each system (CentOS where it works and Ubuntu where it does not work). There seem to be references to a wait.h file where rusage is actually defined, just the same.

What else could I possibly be missing in my Ubuntu environment?

Edit: Adding more MCVE-ish details...

My build is stopping with the following error:

vmodem.c:6747: error: storage size of 'rusage' isn't known

That line in the file is simply:

struct rusage rusage

The required includes are all in that file as well (<sys/time.h>, <sys/wait.h>, etc.)

Not sure what else I can provide in this case...

2

There are 2 answers

1
Mark Plotnick On BEST ANSWER

The man page for getrusage on both CentOS 6 and Ubuntu 14.04 says that one should include <sys/time.h> and <sys/resource.h>.

You mentioned that you include <sys/wait.h>. It has a forward declaration struct rusage; so that the declarations of wait3 and wait4 will be valid, but that forward declaration isn't sufficient to let you declare a struct of type rusage.

Things work on CentOS 6 because CentOS 6's wait.h contains a line #include <sys/resource.h>, and resource.h does fully declare struct rusage, but Ubuntu 14.04's wait.h does not contain a #include <sys/resource.h> line.

0
csr19us On

Thanks to coredump and Eugene Sh. for the tips... adding #include <sys/resource.h> was the trick.

It must have been something that worked in CentOS but not Ubuntu. At any rate, simply including the resource header file shouldn't hurt anything.