From: Tom Seddon Newsgroups: comp.os.msdos.djgpp Subject: Re: Beginner: C / Allegro: "-lalleg" Date: Mon, 29 Dec 1997 00:42:23 +0000 Distribution: world Message-ID: References: <34a65d39 DOT 1813898 AT news2 DOT frankfurt DOT netsurf DOT de> NNTP-Posting-Host: sunholme.demon.co.uk MIME-Version: 1.0 Lines: 45 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In article <34a65d39 DOT 1813898 AT news2 DOT frankfurt DOT netsurf DOT de>, Bjoern Appel writes >Hello, >I'm new to the C-language and installed the DJGPP, RHIDE and Allegro >software. (This is great stuff :-)) >When I want to compile a Allegro-Program, lets say the example, I have >to type: > >gcc ex1.c -o ex1.exe -lalleg <-' > >No, I don't have any problems with it, everything works fine. But can >someone explain me, why I have to use the "lalleg" ? Why is it not >enough to have the "#include" in the source-file, compared >to Pascal's "Uses Crt,..." ? The file "allegro.h" just contains declarations for new types and functions contained in the allegro library. Thus when you use (say) set_gfx_mode, the compiler knows how many parameters this function takes, and of what type each is; it knows because of the declarations in allegro.h. There is little or no code in allegro.h; the code that makes up the functions is contained in a file called liballeg.a (perhaps in your DJGPP\LIB directory). When the compiler compiles the C file, it produces an object file, with code nearly suitable for straight placing into the executable with the exception that any calls to functions outside of that file are not valid (it also lacks startup and shutdown code, amongst other things). However, the names of the functions called are also in the file and so in the next stage of compilation (the linking phase) the compiler searches for functions of the same name inside any of the library files so that it can fix up the calls and generate a runnable EXE program. If you do not specify -lalleg on the command-line, it searches through the libraries it knows about (standard C/C++) without looking in any others, fails to find any of the functions you have called (eg set_gfx_mode) and will terminate with an error and without an EXE. (Try it.) As for the Pascal approach, I'm not sure because I try to stay away from PAscal as much as it possible. I think the .H file contains the equivalent of the Pascal "interface" section of a unit, and the library contains the "implementation" section in compiled form. But don't quote me :-) (I hope I'm not wrong about the first bit either ;-| ) -- Tom Seddon