Windows 中没有定义 timespec 吗?
我觉得很奇怪,这个答案很难找到。我已经包含了 time.h 和 ctime,但 vc9 仍然抱怨未定义的类型“timespec”。我在这里、MSDN 和网络上进行了搜索(即使有确切的编译器错误),但我找不到答案......也许它只是迷失在噪音中。
这是确切的错误:
error C2027: use of undefined type 'timespec'
谢谢
It seems weird to me that this answer is hard to find. I've included time.h and ctime, but vc9 is still complaining about an undefined type 'timespec'. I've searched here, MSDN, and the web (even with the exact compiler error), but I can't find the answer... maybe it's just lost in the noise.
Here's the exact error:
error C2027: use of undefined type 'timespec'
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
struct timespec
来自 posix,通常在 UNIX 上找到,但在 Windows 上找不到。struct timespec
comes from posix, and are typically found on unixes, but not on windows.如果您尝试在 Windows 下编译具有 *nix-y 出处的代码,那么您可能最好使用 cygwin 和 gcc 之类的东西,它们为您提供了一个类似 *nix 的环境。
If you are trying to compile code with a *nix-y provenance under Windows then you might be better off with something like cygwin and gcc, which gives you a *nix-like environment.
尝试包含 pthread.h 。这就是我的 ming32 编译器中定义 timespec 的地方,该编译器与 Codeblocks 一起打包。
为什么?我不知道。只是...
解决方案2...
您不需要预先定义的时间规范!你可以自己定义!这就是 mingw 所做的!
您甚至不必创建 timespec。您可以创建 struct Fun 或 struct Jav::timespec;具有相同的结构并将其转换为 timespec*。当确实定义了 timespec 时,这样做可以使您的代码更具可移植性。
Try including pthread.h . That is where timespec is defined in my ming32 compiler that comes packaged with Codeblocks.
Why? I dont know. Just...
Solution 2...
You dont need a prefined timespec! You can define it yourself! Which is what mingw does!
You dont even have to create timespec. You can create struct Fun or struct Jav::timespec; with the same structure and cast it to timespec*. Doing this makes your code more portable when indeed timespec is defined.