Easy linker problem

Brian Dessent brian@dessent.net
Tue Nov 28 03:47:00 GMT 2006


"Walliss, Darren" wrote:

> I want to use function 'sleep' in a program.
> 
> When I compile my test prog with < gcc sleepTest.c -o sleepTest
> -mno-cygwin >

Using -mno-cygwin is the same as using MinGW, that is, you are using
MSVCRT.DLL as your C library.  There is no such function "sleep()" in
MSVCRT.  There is the win32 API function "Sleep()" (note case) which is
what you should use.  There is an old deprecated and unsupported
"_sleep()" in MSVCRT but you should not use that.

<http://msdn.microsoft.com/library/en-us/dllproc/base/sleep.asp>

> - how do I know which lib to use an a given situation, is there a
> reference out there somewhere??

The entire win32 API is documented quite well on MSDN, and each function
tells you precisely what header to include and what library to link
against.  You can directly translate what MSDN says for "link against
foo.lib" to -lfoo on the gcc link command line.  But the common system
libraries (-lkernel32 -luser32 -ladvapi32 -lshell32) are included in the
specs file by default so you don't need to manually link against those.

Brian



More information about the Gcc-help mailing list