我正在处理这个名为timeKeeper.h(和.c)的大型项目中的文件
--------------编辑---------------修复了那些仍然被破坏的人------------- -
#ifndef TIMEKEEPER_H_
#define TIMEKEEPER_H_
#include <time.h>
#include <stdbool.h>
bool isAfter(time_t time);
void setTime(char seconds, char minutes, char hours, char day,
char month, char year);
void tickSeconds(void);
time_t getCurrentTime(void);
time_t createTime(char seconds, char minutes, char hours, char day,
char month, char year);
void startTime(void);
time_t addSeconds(int seconds, time_t time);
long timeRemaining(time_t time);
void rtc_set(char seconds, char minutes, char hours, char days, char months,
char year);
#endif
Run Code Online (Sandbox Code Playgroud)
当我尝试构建我的项目时,此文件中有一堆错误(以及任何使用time.h的文件).以下是timeKeeper.h中的一些错误:
expected ')' before 'time' Line 6
expected '"', ',', ';','asm', or '__attribute__' before 'getCurrentTime' Line 10
Run Code Online (Sandbox Code Playgroud)
我怀疑timeKeeper不知道time_t是什么,即使它有
#include <time.h>
Run Code Online (Sandbox Code Playgroud)
我也遇到了错误
implicit declaration of function 'localtime'
Run Code Online (Sandbox Code Playgroud)
在我的timeKeeper.c文件中.是的,timeKeeper.c #includes timeKeeper.h
任何帮助是极大的赞赏.
----附加信息-----我正在使用Atmel Studio 6.0这是timeKeeper.c
#include "FreeRTOS.h"
#include "task.h"
#include "print_funcs.h"
#include "timeKeeper.h"
#include "telemetryLookup.h"
void timeTask(void* pvParameters);
time_t TIME;
blah blah blah......
Run Code Online (Sandbox Code Playgroud)
----编辑2 ------
我添加#include <stdbool.h>并更改Bool为bool第6行,但错误仍然存在.
BoolC中没有类型.有一种类型bool,但只有你有类型才可见#include <stdbool.h>.
当我添加#include <stdbool.h>和更改Bool时bool,您的代码编译没有错误.(我还必须删除行号.)
我还建议选择一个名称,而不是time参数isAfter和其他功能.time也是在中声明的函数的名称<time.h>.在这种情况下,我认为它实际上不会导致冲突,但是唯一的名称可以避免混淆.
因为Bool是无法识别的类型名称,编译器会报告语法错误
Bool isAfter(time_t time);
Run Code Online (Sandbox Code Playgroud)
您之后看到的任何错误都可能是虚假的.如果出现语法错误,请首先在最早报告的行上修复错误,然后重新编译.
编辑:
根据进一步的评论,添加#include <stdbool.h>和更改Bool,以bool不出现都有帮助.你得到的特定信息似乎意味着time_t不被认可 - 这当然不会发生.
尝试一个简单的2行源文件(并确保文件名有.c后缀):
#include <time.h>
time_t foo;
Run Code Online (Sandbox Code Playgroud)
如果失败了,我能想到的唯一解释是你的编译器和/或运行时库安装以某种方式被破坏了.
您是否有查看预处理来源的选项?如果是这样,将它应用于上述2行源应该显示预处理的内容<time.h>,其中应包括的定义time_t.