delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/13/20:19:09

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Libs
Date: Sat, 13 Dec 1997 14:59:22 +0000
Organization: Two pounds of chaos and a pinch of salt
Lines: 47
Message-ID: <3492A2CA.3325@cs.com>
References: <3490272F DOT 6AF83CAC AT spam DOT me>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp205.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ryan McGee wrote:
> 
> I'm interested in compiling a file into a library, but I cant find a
> help file telling me how to do this.  Can anyone help me?

Libraries are created for the purpose of storing object files.  To this
end, the first step in creating a library is to compile your code to
objects with the '-c' parameter:

  gcc -Wall -g -O2 -c foo.c bar.c baz.c

The second step is to build the library.  The GNU Binutils come with a
utility called 'ar' to manage archives (libraries).  The syntax to add
object files to a library is thus:

  ar rvs libjunk.a foo.o bar.o baz.o

The third step is to use the library.  If you place 'libjunk.a' in a
location on the LIBRARY_PATH (defined in djgpp.env), then you can link
it using the '-l' parameter like any other library:

  gcc -Wall -g -O2 -o myprog.exe myprog.c -ljunk

If you want to link it from a nonstandard directory, you can use the
'-L' parameter to tell the linker where to look.  The following code
tells ld to look in the current directory as well as any defined in
LIBRARY_PATH:

  gcc -Wall -g -O2 -o myprog.exe myprog.c -L. -ljunk

You can, of course, specify the filename manually, causing gcc to treat
the library like any other file:

  gcc -Wall -g -O2 -o myprog.exe myprog.c libjunk.a

For more information, read the docs of 'ar', and look in chapters 6 and
8 of the FAQ.

hth

-- 
---------------------------------------------------------------------
|      John M. Aldrich       | "A woman is not property, and hus-   |
|       aka Fighteer I       | bands who think otherwise are living |
|   mailto:fighteer AT cs DOT com   | in a dreamworld."                    |
| http://www.cs.com/fighteer |                - Lazarus Long        |
---------------------------------------------------------------------

- Raw text -


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