www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/17/15:00:44

From: George Foot <mert0407 AT sable DOT ox DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Where am I supposed to put bcd.h?
Date: 17 Jun 1998 09:07:17 GMT
Organization: Oxford University, England
Lines: 62
Message-ID: <6m8105$m1k$2@news.ox.ac.uk>
References: <28236d55 DOT 3587767b AT aol DOT com>
NNTP-Posting-Host: sable.ox.ac.uk
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Wed, 17 Jun 1998 03:55:38 EDT in comp.os.msdos.djgpp
FaehnTim AT aol DOT com wrote:

: I think I need to know how to install libraries in general.  Do I only need a
: library (such as *.a) in the c:\djgpp\lib directory or do I need the
: *[.h|.c|.o] somewhere, also?  If so, where?

The first thing you should do is read the instructions which
(hopefully) come with the library.  If it has a makefile, use that
rather than compiling and installing it by hand.  I don't know about
BCD; these are general comments.

If you must install a library by hand, you should compile to object
files then use the `ar' utility to create a library file, normally by
typing something like:

    ar rs libfoo.a foo.o bar.o

The `lib' prefix and `.a' extension are important.

Next, copy the library's include file to the djgpp include directory
and the library file to the djgpp lib directory.  Now you should be
able to compile your code by including the header in any source files
that call the library, and linking in the library when creating an
executable using the `-l' switch.  For example:

    #include <foo.h>
    
    int main (void)
    {
        foo();
        return 0;
    }

Save as `myfile.c', then compile:

    gcc -c -O2 -g -Wall -Werror myfile.c

That creates `myfile.o', then you link:

    gcc -o myfile.exe myfile.o -lfoo

gcc adds the `lib' and `.a' itself to make the library name
`libfoo.a'.  You must put libraries at the *end* of your linking
command line, and if they depend upon one another you need to put the
depended-upon libraries last (or put -( and -) switches around all of
the troublesome libraries).

If the process of creating the library is difficult for you (and the
documentation doesn't help) then you could just include the library's
source files in your project, as if they were your own.

References:
    Documentation for `ar':  info binutils ar
    Documentation for command line switches of `gcc':  info gcc invoking
    "Unresolved externals when linking programs":  DJGPP FAQ section 8.7
    Must put libraries last on the command line:  DJGPP FAQ section 8.9

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

xu do tavla fo la lojban  --  http://xiron.pc.helsinki.fi/lojban/lojban.html

- Raw text -


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