I have a program written with Windows-only code that I'm converting to multi platform. I've taken the windows only function,
Sleep(unsignedint milliseconds);
and am replacing it with
sleep(unsignedint seconds);
I'm getting an error "undefined reference to "sleep(unsigned int)".
The article that describes my sleep function states that it needs "unistd.h" within the program for it to work. I have that included within the source code, so I am confused as to why it is not defined. Would you help me?
Here is where I have <unistd.h> included. My entire project is within one source file.
1 2 3 4 5 6 7
#include <iostream>
#include <string> // for use of strings
#include <limits> // for use of "cin.ignore();"
#include <unistd.h>
unsignedint
sleep(unsignedint seconds);
Here is an example of how I am using the sleep function.
Removed it, getting the error that sleep is now undeclared. What's the problem? I've heard that DevC++ contains the required libraries and headers for unistd.h to be included properly. I haven't edited the compiler at all.
I'm trying to find a function that's multi platform, so I can't use Sleep (which is windows specific). How am I supposed to make this program multi platform if I can't compile it on Windows?
You just make a wrapper function that calls the correct function depending on the platform.
Or you use an existing multi-platform library that does just that.