Template "redefinition" linker error. (attempt #2)

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
 
V

Victor Bazarov

Robbie said:
[...]
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 [...]

Linking is not defined by C++. Whatever you do to get where you
are is implementation-defined. You are probably much better off
asking this in the newsgroup dedicated to your compiler/linker.
Just a thought...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,962
Messages
2,570,134
Members
46,692
Latest member
JenniferTi

Latest Threads

Top