From: Roger W. <ROG...@sa...> - 2007-05-18 19:36:53
|
Brian Dessent wrote: not so fast. when I am using MinGW with gcc 3.3.1 code using sleep() compiles, links and runs as expected on the other hand using MinGW gcc 3.4.5, code using sleep() reports it as an unresolved reference at link time. replacing sleep with _sleep in the source files fixes this. versions: gcc version 3.3.1 (mingw special 20030804-1) GNU ld version 2.13.90 20030111 and gcc version 3.4.5 (mingw special) GNU ld version 2.17.50 20060716 Also sleep is a common function but not completely standard (no mention of it in ISO/IEC 9899 "C" spec). It is, however, included in the POSIX standard. In any case it is dangerous since on Win32 the argument is milliseconds and on POSIX implementations (e.g., RHEL 4.0) the units are seconds. > Charles Sullivan wrote: > > >> What else do I need to install to get the sleep() function? >> > > You have a fundamental misunderstanding of MinGW's purpose if you expect > to port your software unchanged; if that is your goal, you should be > using Cygwin or something else. What MinGW provides is exactly the API > provided by the Microsoft C runtime (MSVCRT) and the Win32 API. sleep() > does not exist in either of those, so it failing to compile is the > expected behavior. > > All of this is documented fully on MSDN. For a list of all functions > provided by MSVCRT: > <http://msdn2.microsoft.com/en-us/library/634ca0c2(VS.80).aspx>. A > suitable replacement is the Win32 API function Sleep() (note the > capitalization difference) > <http://msdn2.microsoft.com/en-us/library/ms686298.aspx>. > > Also note that the footer of every Win32 API function tells you the > necessary header that must be included (in most cases, just #include > <windows.h>) and the libraries that must be linked. You can directly > translate the text "Use Kernel32.lib" to "add -lkernel32 to the link > command line." However, in this case, kernel32 is a pretty basic > library that every program links against (or alternatively put, > -lkernel32 is in the gcc specs file) so there's no need to manually add > it. But the more you use the Win32 API, be aware that some functions > will require nondefault libraries to be specified on the link command > line. > > Brian > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > > -- Roger Wells, P.E. SAIC 221 Third St Newport, RI 02840 401-847-4210 (voice) 401-849-1585 (fax) rog...@sa... |