delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/28/20:32:06

From: Tom Seddon <tom AT sunholme DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Beginner: C / Allegro: "-lalleg"
Date: Mon, 29 Dec 1997 00:42:23 +0000
Distribution: world
Message-ID: <IIDzSLAvHvp0IwpN@sunholme.demon.co.uk>
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

In article <34a65d39 DOT 1813898 AT news2 DOT frankfurt DOT netsurf DOT de>, Bjoern Appel
<Bjoern DOT Appel AT frankfurt DOT netsurf DOT de> 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<allegro.h>" 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019