本文介绍了Ubuntu rusage错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从CentOS 6移植一些真正的旧代码(大量基础)到Ubuntu 14.04.注意,我已经安装了预期的较旧版本的gcc,固定的链接器引用等.

我的构建尝试正在进行中,但是我只能坚持一件事.有一个C文件正在尝试创建类型为rusage的结构,但是Ubuntu环境给了我以下错误:error: storage size of 'rusage' isn't known

据我所知,我所有的路径看起来都是正确的.我什至已经查看了每个系统上的time.h和resource.h系统文件(可以使用CentOS,不能使用Ubuntu).似乎有一个引用实际上是在定义rusage的wait.h文件.

在我的Ubuntu环境中我可能还缺少什么?

添加更多MCVE-ish详细信息...

我的构建因以下错误而停止:

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

文件中的这一行很简单:

struct rusage rusage

必填项也全部包含在该文件中(<sys/time.h><sys/wait.h>等)

不确定在这种情况下我还能提供什么...

解决方案

在CentOS 6和Ubuntu 14.04上,getrusage的手册页上都应该包含<sys/time.h><sys/resource.h>.

您提到您包括<sys/wait.h>.它具有前向声明struct rusage;,因此wait3wait4的声明将有效,但是该前向声明不足以让您声明类型为rusage的结构.

之所以在CentOS 6上起作用,是因为CentOS 6的wait.h包含一行#include <sys/resource.h>,并且resource.h确实声明了struct rusage,但是Ubuntu 14.04的wait.h不包含#include <sys/resource.h>行./p>

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

解决方案

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.

这篇关于Ubuntu rusage错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 20:20