【发布时间】:2011-01-19 19:52:26
【问题描述】:
我觉得这个答案很难找到。我已经包含了 time.h 和 ctime,但是 vc9 仍然在抱怨未定义的类型 'timespec'。我在这里、MSDN 和网络上搜索过(即使有确切的编译器错误),但我找不到答案……也许它只是在噪音中迷失了。
这是确切的错误:
error C2027: use of undefined type 'timespec'
谢谢
【问题讨论】:
我觉得这个答案很难找到。我已经包含了 time.h 和 ctime,但是 vc9 仍然在抱怨未定义的类型 'timespec'。我在这里、MSDN 和网络上搜索过(即使有确切的编译器错误),但我找不到答案……也许它只是在噪音中迷失了。
这是确切的错误:
error C2027: use of undefined type 'timespec'
谢谢
【问题讨论】:
struct timespec 来自 posix,通常在 unix 上找到,但在 windows 上找不到。
【讨论】:
如果您尝试在 Windows 下编译具有 *nix-y 出处的代码,那么使用 cygwin 和 gcc 之类的东西可能会更好,这会为您提供类似 *nix 的环境。
【讨论】:
尝试包含 pthread.h 。这就是我在与 Codeblocks 一起打包的 ming32 编译器中定义 timespec 的地方。
为什么?我不知道。就……
#include <time.h>
#ifndef POSIX MORALITY
#include <pthread.h>
#endif
解决方案 2... 您不需要预定义的时间规范!你可以自己定义! mingw 就是这样做的!
struct timespec { /* details */ };
您甚至不必创建 timespec。您可以创建 struct Fun 或 struct Jav::timespec;具有相同的结构并将其转换为 timespec*。当确实定义了 timespec 时,这样做会使您的代码更具可移植性。
【讨论】: