包含标头不起作用
Including header doesn't work
我正在尝试一个在time.h
和sys/time.h
标头中使用多个声明的库。无论我做什么,我都无法使用任何 cpp 文件中的标头。定义似乎根本没有定义。
这就是 time.h 的样子——
#ifndef IW_STD_TIME_H
#define IW_STD_TIME_H
#include <sys/types.h>
#ifndef _TIME_T_DEFINED
#define _TIME_T_DEFINED
typedef long time_t;
#endif
#define CLOCKS_PER_SEC 1000
#ifndef _CLOCK_T_DEFINED
typedef long clock_t;
#define _CLOCK_T_DEFINED
#endif
#ifndef _TM_DEFINED
struct tm
{
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
#define _TM_DEFINED
#endif
struct timespec
{
time_t tv_sec; /* Seconds. */
long int tv_nsec; /* Nanoseconds. */
};
S3E_BEGIN_C_DECL
#ifdef __ARMCC_VERSION
#define localtime localtime_rvct
#define localtime_r localtime_rvct_r
#endif
time_t time(time_t *t);
void tzset(void);
char *asctime(const struct tm *tm);
char *asctime_r(const struct tm *tm, char *buf);
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
struct tm *gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
time_t mktime(struct tm *tm);
size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
clock_t clock(void);
double difftime(time_t time1, time_t time0);
int nanosleep(const struct timespec *req, struct timespec *rem);
#if defined __GNUC__ && !defined __APPLE__ && !defined I3D_ARCH_MIPS
extern char *_tzname[2];
extern int _daylight;
extern long int _timezone;
#define tzname _tzname
#define daylight _daylight
#define timezone _timezone
#else
extern char *tzname[2];
extern int daylight;
extern long int timezone;
#endif
#define CLOCK_REALTIME 1
#define CLOCK_MONOTONIC 2
typedef int clockid_t;
int clock_getres(clockid_t clk_id, struct timespec *res);
int clock_gettime(clockid_t clk_id, struct timespec *tp);
int clock_settime(clockid_t clk_id, const struct timespec *tp);
S3E_END_C_DECL
#include <sys/time.h>
#endif /* !IW_STD_TIME_H */
这就是 sys/time.h 的定义 -
#ifndef IW_STD_SYS_TIME_H
#define IW_STD_SYS_TIME_H
#include "s3eTypes.h"
#include <time.h>
#ifndef _WINSOCK2API_
S3E_BEGIN_C_DECL
#ifndef _TIME_T_DEFINED
#define _TIME_T_DEFINED
typedef long time_t;
#endif
typedef long suseconds_t;
struct timeval
{
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
struct timezone
{
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of DST correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);
int utimes(const char *filename, const struct timeval times[2]);
S3E_END_C_DECL
#endif // XBOX
#endif // !IW_STD_SYS_TIME_H
我将它们作为#include<time.h>
包含在 cpp 文件中,甚至typedef long time_t;
都不起作用。但是,当我将声明放在 cpp 文件本身中时,它可以工作。我确定我在这里错过了一些愚蠢的东西。知道吗?
PS:文件中提到的宏是这样定义的-
#define S3E_BEGIN_C_DECL extern "C" {
#define S3E_END_C_DECL }
更新:
错误是这样的——
错误3 错误 C2079:"tv"使用未定义的结构"timeval"错误 4 错误 C3861:"获取一天的时间":找不到标识符
似乎根本没有定义标头中的所有定义。这些标头到处都在发生这种情况。
哦,
这是因为我的项目中已经有一个time.h
,并且使用#include_next
指令替换默认标头。我之前注释掉了该指令,所以我想这就是为什么 IDE 显示正确的文件,但编译器会考虑替换的文件。我用#include
更改了#include_next
,放置了默认文件的更具体的路径,错误解决了。
相关文章:
- 仅包含可移动 std::map 的类的移动构造函数不起作用
- 无法打开包含文件'Graphics.hpp'没有这样的文件或目录,Visual Studio的其他包含不起作用
- 其他包含目录不起作用
- std::包含 std::函数回调的多个包装器的向量不起作用
- 提升库无法在C++中工作,包含目录不起作用
- 在 C++ 中,.h 文件包含文件但不起作用
- Visual Studio 2015 中的其他包含目录不起作用
- C++ 包含防护不起作用,错误
- C++ -- 指向结构数组的指针,该数组包含指向不起作用的类数组的指针
- XCode更新后,标头文件在CLION中不起作用
- C++接口(标头)和实现文件不起作用
- 在我试图创建一个载体中包含C 中的唯一元素的矢量时,发现不起作用
- 包含标准标头后,Vim 代码补全不起作用
- Android NDK 中的某些 c++ 包含文件不起作用
- 字符串下标超出范围.我不知道如何使用字符索引数组,所以我使用了(无符号整数),但它不起作用
- 如果向量包含重复项,则此函数应返回 true。知道为什么它不起作用吗?
- 如果函数包含在命名空间中,则"go to beginning of the function"不起作用 (C++)
- Qt .pro文件:添加包含"include"目录的路径不起作用
- 包含标头不起作用
- 为什么带有包含标头的生成文件不起作用?