Mail Archives: djgpp/1994/10/15/03:41:24
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 -