I have two problems with the code below:

1. I cannot find a header file to #include that has the sleep function prototype.

2. When I add my own sleep function prototype, I get an unresolved external reference error (for _sleep, not sleep).

What must I #include to get the sleep function prototype?

What lib must I include in the linker configuration to resolve the external reference?

(I suspect that if I #include the correct header file, the second question might become moot.)


The "man page" at http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx says the header file is <WinBase.h>.

But #include'g only <WinBase.h> results in compilation errors.

A response marked "answer" at http://social.msdn.microsoft.com/For...1-75084ad53f7d says <windows.h> [sic].

#Include'g only <Windows.h> does eliminate the compilation errors.

But apparently that does not bring in the sleep function prototype. Neither does also subsequently #include'g <WinBase.h>.

(Which seems to be #include'd by <Windows.h> anyway.)


But even with my own function prototype shown below, I get an unresolved external reference for _sleep.

Note: not for sleep per se. Is that a symptom of my problem: my sleep reference is changed to _sleep? If so, how can avoid that?

According to "man page" (see link above), the external should be resolve in kernel32.lib.

And kernel32.lib does appear in the "Additional Dependencies" list under Configuration Properties \ Linker \ Input.

PS: Since I am not using C++ features, I tried setting "Compile as C" under Configuration Properties \ C/C++ \ Advanced, to no avail.


My code....

#include "stdafx.h"
#include <stdlib.h>
#include <time.h>
#include <Windows.h>
void sleep(DWORD msec); // added later

int _tmain(int argc, char* argv[])
time_t st, et;
st = time(NULL);
et = time(NULL);
printf("%ld\n%ld\n%ld\n", st, et, et-st);
printf("press Enter to terminate");
return 0;