delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/20/23:32:07

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Libs and dissassembly (again)
Date: Mon, 20 Jan 1997 20:27:42 -0800
Organization: Two pounds of chaos and a pinch of salt
Lines: 67
Message-ID: <32E445BE.5DB@cs.com>
References: <01bc0686$36fa7820$3957f8ce AT 698130>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp211.cs.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Craig Flint wrote:
> 
> I'm new at DJGPP and I coudln't figure out how to compile libs.  As well I
> couldn't figure out how to dissassemble an object file (if it is possible
> in DJGPP) or view the assembly code that DJGPP produces from a C or C++
> file.

To make a library, compile a bunch of files with the -c option to make
object files (.o).  Then use the 'ar' command as follows:

ar rvs libmylib.a file1.o file2.o file3.o ...

ar will complain the first time you create the library (you can stop
this by adding the 'c' flag) but aside from that this is all you need. 
Look up 'ar' in the docs for more information (it's in the binutils).

To link the library, you need to do one of three (well, four) things:

1) Put the library in with the rest of the DJGPP libraries and link with
'-lmylib'.  This is not really good because it creates the possibility
of confusing your library with a "standard" library.

2) Keep the library in a separate directory, and use the '-L' switch to
tell the compiler the name of the directory.  For example, say your
program is in C:\PROGS.  Then use this command:

  C:\PROGS\> gcc -Wall -O -g -o myprog.exe myprog.c -L. -lmylib

Most distributed programs use this technique for libraries they create
or are distributed with.

3) Keep the library in a separate directory, and add an entry to the
LIBRARY_PATH in 'djgpp.env' indicating what the directory is.  You can
then link it like any other library without needing the '-L' option. 
This is only a good idea if you want the library to be available to ANY
program you write, and don't want to put it in the DJGPP lib directory.

4) This isn't a good choice at all, but you can manually force the
library to be linked by putting it on the command line like any other
file.  Thus:

  gcc -Wall -o -g -o myprog.exe myprog.c libmylib.a

will do what you want, but it's very kludgy and not recommended.  ld
provides the '-l' directive for a reason; you should always endeavor to
use it.  :)

As far as viewing the compiled assembly code of your programs, you have
two options.  The first is to run your compiled program under a
low-level debugger like fsdb.  Then you can step through your machine
code directly and see its effects as it runs.  The other is to use the
'-S' option while compiling to have the compiler emit assembly code
instead of object code.  Note that case is always important for gcc
command-line options!

Hope this helps!

P.S.:  I think I recall your original post, and I thought several people
responded.  Perhaps you just missed it?

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
| "Starting flamewars since 1993"  |   http://www.cs.com/fighteer   |
|  *** NOTICE ***  This .signature is generated randomly.           |
|                  If you don't like it, sue my computer.           |
---------------------------------------------------------------------

- Raw text -


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