Mail Archives: djgpp/1998/06/17/15:00:44
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 -