无效使用未定义类型&储存空间未知 [英] invalid use of undefined type & storage size unknown
本文介绍了无效使用未定义类型&储存空间未知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将某些功能移到 c
项目中的单独文件中.
I am trying to move some functions to separate file in c
project.
我用
#ifndef _UTIL_H
#define _UTIL_H
#include <signal.h>
#include <termios.h>
#include <time.h>
...
extern struct timeval tv1, tv2, dtv;
void time_start();
long time_stop();
我用
制作了 util.c
文件
#include "util.h"
...
struct timeval tv1, tv2, dtv;
void time_start() { gettimeofday(&tv1, &timezone); }
long time_stop()
{
gettimeofday(&tv2, &timezone);
dtv.tv_sec = tv2.tv_sec - tv1.tv_sec;
...
在我拥有的cmake中
in cmake I have
add_executable(mpptd mpptd.c util.c)
在编译过程中出现以下错误
and I get the following errors during compile
[build] ../settings/daemons/util.c: In function ‘time_stop’:
[build] ../settings/daemons/util.c:14:8: error: invalid use of undefined type ‘struct timeval’
[build] dtv.tv_sec = tv2.tv_sec - tv1.tv_sec;
[build] ^
和
[build] ../settings/daemons/util.c: At top level:
[build] ../settings/daemons/util.c:7:16: error: storage size of ‘tv1’ isn’t known
[build] struct timeval tv1, tv2, dtv;
[build] ^~~
这里有什么问题?为什么要存储大小"?错误发生的时间比未定义类型"晚错误?谁不早点去?
What can be wrong here? Why "storage size" error goes later than "undefined type" error? Whouldn't it go earlier?
推荐答案
struct timeval
在sys/time.h中定义.您需要将其包括在内.
struct timeval
is defined in sys/time.h. You'll need to include that.
#ifndef _UTIL_H
#define _UTIL_H
#include <signal.h>
#include <termios.h>
#include <time.h>
#include <sys/time.h>
...
这篇关于无效使用未定义类型&储存空间未知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文