R
Robbie Hatley
I asked about this yesterday, but no one bit. So I'll ask
again. I can be a persistant cuss.
I ran into a problem a few days ago when I added a couple of
template functions to one of my personal library headers.
My library, librh.a, has these objects:
rhutil.o rhdir.o rhmath.o rhbitmap.o
and matching headers:
rhutil.h rhdir.h rhmath.h rhbitmap.h
These had been compiling fine, and linking fine to *.cpp files
which used them. Until a few days ago, when I added a couple
new template functions to rhdir.h. The library modules still
compiled fine, but when I tried to link some other object module,
say "MyNewProgram.o" to rhdir.o, I got a message like this:
rhdir.o: redefinition of template (blah blah blah);
see original definition in MyNewProgram.o
I was able to get this error to go away by declaring the two
new template functions "inline". But why should this be
necessary? Is it normally necessary to declare a template
function in a header as being "inline"?
Perhaps the fact that my module rhutil.o instantiates these
templates has something to do with it? If a compiler first
compiles the non-library object module(s) for a program
(instantiating a template in the processs), then attempts to
link to a pre-exising library object which already contains
an identical instantiation, could that cause problems?
Or should compilers and linkers be able to handle that?
--
Very curious,
Robbie Hatley
Tustin, CA, USA
lonewolfintj atsign pacbell period net
home period pacbell period net slantbar earnur slantbar
again. I can be a persistant cuss.
I ran into a problem a few days ago when I added a couple of
template functions to one of my personal library headers.
My library, librh.a, has these objects:
rhutil.o rhdir.o rhmath.o rhbitmap.o
and matching headers:
rhutil.h rhdir.h rhmath.h rhbitmap.h
These had been compiling fine, and linking fine to *.cpp files
which used them. Until a few days ago, when I added a couple
new template functions to rhdir.h. The library modules still
compiled fine, but when I tried to link some other object module,
say "MyNewProgram.o" to rhdir.o, I got a message like this:
rhdir.o: redefinition of template (blah blah blah);
see original definition in MyNewProgram.o
I was able to get this error to go away by declaring the two
new template functions "inline". But why should this be
necessary? Is it normally necessary to declare a template
function in a header as being "inline"?
Perhaps the fact that my module rhutil.o instantiates these
templates has something to do with it? If a compiler first
compiles the non-library object module(s) for a program
(instantiating a template in the processs), then attempts to
link to a pre-exising library object which already contains
an identical instantiation, could that cause problems?
Or should compilers and linkers be able to handle that?
--
Very curious,
Robbie Hatley
Tustin, CA, USA
lonewolfintj atsign pacbell period net
home period pacbell period net slantbar earnur slantbar