Windows 中没有定义 timespec 吗?

发布于 2024-08-22 22:43:06 字数 230 浏览 2 评论 0原文

我觉得很奇怪,这个答案很难找到。我已经包含了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

影子是时光的心 2024-08-29 22:43:06

struct timespec 来自 posix,通常在 UNIX 上找到,但在 Windows 上找不到。

struct timespec comes from posix, and are typically found on unixes, but not on windows.

九厘米的零° 2024-08-29 22:43:06

如果您尝试在 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.

翻身的咸鱼 2024-08-29 22:43:06

尝试包含 pthread.h 。这就是我的 ming32 编译器中定义 timespec 的地方,该编译器与 Codeblocks 一起打包。

为什么?我不知道。只是...

#include <time.h>

#ifndef POSIX MORALITY
    #include <pthread.h>
#endif

解决方案2...
您不需要预先定义的时间规范!你可以自己定义!这就是 mingw 所做的!

struct timespec { /* details */ };

您甚至不必创建 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...

#include <time.h>

#ifndef POSIX MORALITY
    #include <pthread.h>
#endif

Solution 2...
You dont need a prefined timespec! You can define it yourself! Which is what mingw does!

struct timespec { /* details */ };

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文