-
December 23rd, 2012, 02:51 AM
#1
How to call sleep()?
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);
sleep(2000);
et = time(NULL);
printf("%ld\n%ld\n%ld\n", st, et, et-st);
printf("press Enter to terminate");
getchar();
return 0;
}
-
December 23rd, 2012, 04:53 AM
#2
Re: How to call sleep()?
Possibly you mean Sleep function. Required header is Windows.h.
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
-
December 23rd, 2012, 07:57 AM
#3
Re: How to call sleep()?
Originally Posted by joeu2004
I have two problems with the code below:
1. I cannot find a header file to #include that has the sleep function prototype.
C++ is case-sensitive. The function is Sleep, not sleep.
Regards,
Paul McKenzie
-
December 23rd, 2012, 02:40 PM
#4
Re: How to call sleep()?
Originally Posted by Paul McKenzie
C++ is case-sensitive. The function is Sleep, not sleep.
OMG, I forgot! Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|