From: DavMac AT iname DOT com (Davin McCall) Newsgroups: comp.os.msdos.djgpp Subject: Re: difference between libraries and headers Date: Thu, 18 Nov 1999 02:08:13 GMT Organization: Monash Uni Lines: 45 Distribution: world Message-ID: <38335d9f.2707933@newsserver.cc.monash.edu.au> References: <80vhq4$kvc AT hermes DOT acs DOT unt DOT edu> NNTP-Posting-Host: damcc5.halls.monash.edu.au X-Trace: towncrier.cc.monash.edu.au 942890904 3902 130.194.198.138 (18 Nov 1999 02:08:24 GMT) X-Complaints-To: abuse AT monash DOT edu DOT au NNTP-Posting-Date: 18 Nov 1999 02:08:24 GMT X-Newsreader: Forte Free Agent 1.1/32.230 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Wed, 17 Nov 1999 18:38:10 -0600, "Morpheus" wrote: >I know the difference between a library file and a header file, but can >someone tell me the particulars involved -- the differences between >compiling your program with included headers and including a library on the >prompt? I know the header files on the include path don't contain a full >implementation of their functions/classes, so where is this implementation? In a library file. >If it's in the library files, how does the compiler know which library to >get without specifying it at the prompt? It generally doesn't. In the case of the "standard headers" (eg stdio.h, stdlib.h, string.h), the implementations are contained in the standard library, which is automatically linked in (you don't need to specify it on the command line). For other headers, you generally also need to specify the library file. > If compiling with libraries and >headers are independent things, then what is the advantage of compiling with >library files? Hopefully you understand by now, but to further clarify: Including headers and linking libraries are not completely independent: They supplement each other. In particular, the header file tells the compiler what functions (and variables and types etc) are available in the library, so that it knows how many arguments each of the functions takes and can generate appropriate errors if the wrong number is used, etc. The library on the other hand contains the implementation, which is pre-compiled code. The linker uses the library file by extracting the appropriate code and including it in the program (incidentally, the compiler calls the linker automatically, and passes the appropriate library files as specified by the user. It also adds the standard library at this point). Davin. __________________________________________________________ *** davmac - sharkin'!! davmac AT iname DOT com *** my programming page: http://yoyo.cc.monash.edu.au/~davmac/