Undefined reference to "sleep" but I did include <unistd.h> Undefined reference to "sleep" but I did include <unistd.h> windows windows

Undefined reference to "sleep" but I did include <unistd.h>


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.