Well, this must be a silly one. Here below is a can-not-be-simpler code in C. It can not compile saying "undefined reference to sleep". But I think I include all system header I need...
#include <stdio.h>
#include <unistd.h>
int main()
{
printf("Test starts.\n");
sleep(1);
printf("Test ends.\n");
return 1;
}
Try this at the top:
#ifdef __unix__
# include <unistd.h>
#elif defined _WIN32
# include <windows.h>
#define sleep(x) Sleep(1000 * (x))
#endif
This code will allow you to use two different functions under the same name, that do quite the same thing. And it compiles under different platforms.
Also, parenthesizing the (x)
argument ensures that the delay is right even if someone calls it like this sleep(10+10)
If you are running under the Windows operating system, include windows.h
header file to your program and change sleep()
to Sleep()
.
The problem would get disappeared.
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With