Timespec redefinition error [duplicate] Timespec redefinition error [duplicate] windows windows

Timespec redefinition error [duplicate]


pthreads-win32 (which I assume you're using) may internally include time.h (time.h is also commonly included by other libraries/headers) - and time.h already declares timespec (also, it does so in a way compatible with pthreads) - yet the pthreads-win32's pthread.h doesn't have the valid include guards for this case (shame on them!). pthreads tries to declare it because it needs it internally, but since it's possible it won't need the entire time.h, it tries to declare only the timespec if possible. Still, you can simply add

#define HAVE_STRUCT_TIMESPEC

before #include <pthread.h> - that will tell the pthreads-win32 header that you already have a proper timespec, and will let your code compile properly.

Alternatively, if you're using pthreads extensively, you may wish to edit the header file itself - simply add that #define HAVE_STRUCT_TIMESPEC to it somewhere near the beginning, and you're good to go.

Further reading: http://mingw-users.1079350.n2.nabble.com/mingw-error-redefinition-of-struct-timespec-td7583722.html