Mail Archives: djgpp/1994/08/18/23:21:10
Okay, I admit it - having come from Turbo Pascal, I'm new to "real"
compilers. So I can't figure this out.
What I want to do is compile my graphics library so that it isn't
re-compiled for every program. I was thinking that the object file
format was good for this - the one that ends with .o
So I split my thing up into a header file and a source file and tried
to compile with the "-c" option.
Up to this point, everything is working (at least I think so).
If I compile my .c source without putting the variables in, it doesn't
work (which makes sense). So what I did was include the .h file in the
.c file to get the variables.
That lets the .c file compile to a .o file with no problems.
Now, if I want to use this graphics library in another program, I
#include the .h file. In order for that to work, however, it needs
access to the variables again >>before<< linking so that it can assemble
and know what sizes, etc...
Now here's my problem. The variables are in the .o file AND in the
file I'm currently compiling so I get multiple definition errors at the
linking stage.
Does that make any sense? I know it seems like a jumble to me...
So let me restate the problem. In order to compile graph.c to a .o
file, it needs access to the variables. In order to compile a program
that uses graph.c, it _also_ needs access to the variables. So I end up
with two definitions of each variable used and, thus, no executable program.
Can someone help straighten me out? I'm trying to figure this out on
my own and I just have the feeling that I have some basic
misunderstanding somewhere. :(
Kim
- Raw text -