tjd
tjd

Reputation: 457

Is timespec not defined in Windows?

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

Upvotes: 2

Views: 5186

Answers (3)

user9599745
user9599745

Reputation:

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.

Upvotes: 0

Paul R
Paul R

Reputation: 212959

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.

Upvotes: 0

nos
nos

Reputation: 229088

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

Upvotes: 5

Related Questions