我正在尝试将一些函数移动到单独的文件中c
项目。
I made util.h
文件与
#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中我有
add_executable(mpptd mpptd.c util.c)
我在编译过程中收到以下错误
[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] ^
and
[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] ^~~
这里可能出了什么问题?为什么“存储大小”错误晚于“未定义类型”错误?谁不早点走?