March 10, 2008 Archives

10-03-2008 15:05

Cross compile and sleep()

So I wanted to write a little app that was console based and used a sleep function to delay some printing out of lines. I got it working on Linux easy enough by using the usleep() function. This counts in microseconds, so 2000000 = 2 seconds. You can use the sleep() that uses seconds by including the unistd.h library.?

Now to compile a c++ app on Windows that has a sleep like function was a little trick using GNU tools. I finally found out that you need to use the Win32 API call of Sleep() thats found in the windows.h library. MS Sleep function. To compile in Cygwin you would use:

g++.exe -mno-cygwin <source> -o <outputname>

And then to compile on a Linux native system:

i586-mingw32msvc-c++ <source> -o <outputname>

Now there must be a way to use the sleep function thats in the dos.h libraries under Windows as you can include that library when compile under Cygwin or Linux. But either way, I have found a way to get it done and use the Win32 API call function of Sleep() found in the windows.h library by simply including that.

This thread was interesting and important in me workign this out. http://www.dreamincode.net/forums/showtopic16391.htm


Posted by DaveQB | Permanent Link