Ubuntu rusage error [closed]

爱⌒轻易说出口 提交于 2020-01-07 03:07:08

问题


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...


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/34517362/ubuntu-rusage-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!