delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/14/12:32:05

Date: Sun, 14 Dec 1997 09:28:43 -0800 (PST)
Message-Id: <199712141728.JAA17105@adit.ap.net>
Mime-Version: 1.0
To: "Hugo Jose Ferreira" <hugojf AT mail DOT telepac DOT pt>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Library Problem ! Help !

At 12:27  12/14/1997 -0500, Hugo Jose Ferreira wrote:
>Hi !
>I've got a problem with the following:
>
>I've started to port my graphics libraries to DJGPP. In order to do that,
>I've created a .h file which contained every routine... for example, video.h
>contains:
[snipped]
>This was Ok, until I've started to port everything i programmed under 16bit
>TP&ASM, and noted that my executables files were getting large... I've
>realised that, every function I've putted in the .h file, was being compiled
>into the executable, even if it isn't used by the program...
>
>My question is: HOW CAN I FIX THIS !!!! Maybe putting all the functions in
>the header file ISN'T the proper way of doing a library... But... my
>question is: how can I tell the linker to not include the functions I'm not
>using ?!?!?
You're correct. This isn't the best way to do it. The canonical (and most
efficient) method is to have one big header file containing declarations,
macros, and inline functions:

int func(void);
#define FOO 12345
inline int addone(int x) { return x + 1; }

Then break the actual source up into files, one function per file, and have
each include the header. Compile each one with `-c' to produce an object
file, then use `ar' (see its docs under Binutils) to archive them all in a
library.

When you write a program that uses the library, have it #include your header
file, and link with the library.

You might look at how Allegro or some other library is structured if you
want an example.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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