向NMAKE命令行传递HAVE_STRUCT_TIMESPEC无法解决pthread-win32编译问题
Let’s tackle your build issues one by one—both the timespec redefinition error and the C4996 warning are common headaches when building older libraries like pthread-win32 2.7.0 with VS2015.
1. Resolving the error C2011: 'timespec': 'struct' type redefinition
You’re correct that HAVE_STRUCT_TIMESPEC should fix this, but the problem is likely how you’re passing the preprocessor definition to NMAKE. VS’s compiler doesn’t recognize standalone macro definitions on the NMAKE command line—you need to inject it into the CFLAGS variable that the Makefile uses for compiler flags.
Try running this command instead:
nmake VC-static CFLAGS="/DHAVE_STRUCT_TIMESPEC"
This tells the compiler to define HAVE_STRUCT_TIMESPEC before compiling, which skips pthread-win32’s custom timespec struct definition (since VS2015 already provides this struct in system headers).
2. Eliminating the warning C4996: '_ftime…'
The C4996 warning pops up because VS2015 marks legacy functions like _ftime as "unsafe" and encourages using newer alternatives. To suppress this warning globally for the build, add the _CRT_SECURE_NO_WARNINGS preprocessor definition to your CFLAGS:
Combine both fixes into one command:
nmake VC-static CFLAGS="/DHAVE_STRUCT_TIMESPEC /D_CRT_SECURE_NO_WARNINGS"
Alternative: Persist the Fixes in the Makefile
If you don’t want to type the long command every time, edit the Makefile.vc in your pthread-win32 checkout:
- Locate the section defining
VC_CFLAGS(it should look something likeVC_CFLAGS = $(CFLAGS) /O2 /W3 /MT) - Append the two preprocessor definitions:
VC_CFLAGS = $(CFLAGS) /O2 /W3 /MT /DHAVE_STRUCT_TIMESPEC /D_CRT_SECURE_NO_WARNINGS - Save the file, then run
nmake VC-staticas usual—your fixes will apply automatically.
After making these changes, your build should complete without the timespec redefinition error and the C4996 warning.
内容的提问来源于stack exchange,提问作者Fantastic Mr Fox

