Win32 App - Undefined struct 'timespec' when using VS 2013

Comments, questions, bug reports, etc.
Post Reply
don
Posts: 9
Joined: Fri Nov 11, 2016 7:13 pm

Win32 App - Undefined struct 'timespec' when using VS 2013

Post by don »

When using Visual Studio 2013, if you reference only the headers mentioned in the docs (wimlib.h, wimlib_tchar.h) and build an otherwise empty project, you receive the following errors:

Error 1 error C2079: 'wimlib_dir_entry::creation_time' uses undefined struct 'timespec' wimlib.h
Error 2 error C2079: 'wimlib_dir_entry::last_write_time' uses undefined struct 'timespec' wimlib.h
Error 3 error C2079: 'wimlib_dir_entry::last_access_time' uses undefined struct 'timespec' wimlib.h
Warning warning C4200: nonstandard extension used : zero-sized array in struct/union wimlib.h

Here are repro steps:

1. File > New Project > Visual C++ > Win32 > Win32 Console Application
2. Leave defaults for Win32 Application Wizard
3. Copy wimlib.h and wimlib_tchar.h from wimlib-1.10.0\source\include to your project folder.
4. Project > Add Existing Item... > Select both wimlib.h and wimlib_tchar.h
5. Add #include "wimlib.h" to the top of your project's main CPP file (e.g. ConsoleApplication#.cpp)
6. Build > Build Solution

Same is true for the source examples such as capturewim.c. Normally I would attempt to resolve and post findings, however this appears to deal with POSIX and time resolution, both subjects of which I'm no expert.
don
Posts: 9
Joined: Fri Nov 11, 2016 7:13 pm

Re: Win32 App - Undefined struct 'timespec' when using VS 2013

Post by don »

FWIW, this is a non-issue on Visual Studio 2015 as Microsoft decided it was finally "time" to define timespec. You can find it in the time.h included in version 10 of the Windows Kits:

C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\time.h

#ifndef _CRT_NO_TIME_T
struct timespec
{
time_t tv_sec; // Seconds - >= 0
long tv_nsec; // Nanoseconds - [0, 999999999]
};
#endif

- Don
synchronicity
Site Admin
Posts: 474
Joined: Sun Aug 02, 2015 10:31 pm

Re: Win32 App - Undefined struct 'timespec' when using VS 2013

Post by synchronicity »

Yeah, the use of 'struct timespec' in the API was probably a mistake. The solution will be to define a compatible structure in wimlib.h for Visual Studio to use. I don't have a Visual Studio setup right now but you can try my proposed fix at https://wimlib.net/git/?p=wimlib;a=blob ... 4ce5199f9c. (It's also at branch msvc_fix in the git repository.)
synchronicity
Site Admin
Posts: 474
Joined: Sun Aug 02, 2015 10:31 pm

Re: Win32 App - Undefined struct 'timespec' when using VS 2013

Post by synchronicity »

Fix is included in wimlib-1.11.0-BETA1, and wimlib.h is now included in the Windows binary release files too.
Post Reply