delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/10/15/03:41:24

Date: Sat, 15 Oct 94 15:53:12 JST
From: Stephen Turnbull <turnbull AT shako DOT sk DOT tsukuba DOT ac DOT jp>
To: OKRA AT max DOT tiac DOT net
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu
Subject: combining .o files - nevermind

     I'm not so interested in making .a files anymore since I realized that 
   putting "*.o" on the command line works great.

Well, yes and no, because ...

     Now I have a different question.  How can I make my library functions 
   so that I can redefine them?  For instance, the math library sin() can be 
   redefined in a program and it'll use the one you wrote instead.  But if I 
   have a function in my graph lib called WaitRetrace and I try to compile a 
   program that re-did WaitRetrace(), it'll error at linking.

The loader (ld) assumes that you, the programmer, know what you're
doing most of the time.  If you want to define sin(), then you should
be able to do so.  On the other hand, the default is to use the
library's version.  Thus, .o and .a files are treated differently.
    .o files are the programmer's responsibility, and the loader
assumes you want to use all functions defined in them.  So you may not
have duplicate definitions.  .a files contain "default versions" of
commonly used functions, and the compiler will search them for
"unresolved externals".  So for example

    ld -o trig_eg trig_eg.o sin.o -lm

will work and use your sin(), and

    ld -o trig_eg trig_eg.o -lm sin.o

should fail because of multiple definitions of sin().  So you really
want to make your graph lib into a true (.a) lib, using

    ar -r libgraph.a WaitRetrace.o DisplayGIF.o CensorPornoJPEG.o ...

Check out `ar' in your Info or man pages.  Note that in older versions
the `ranlib' operation failed dismally in the DJGPP package, to the
point of hanging your machine.

- Raw text -


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