467,877 Members | 1,257 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,877 developers. It's quick & easy.

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

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

Jun 28 '06 #1
  • viewed: 1721
Share:
1 Reply
Robbie Hatley wrote:
[...]
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by lomat | last post: by
8 posts views Thread by TTroy | last post: by
reply views Thread by Robbie Hatley | last post: by
2 posts views Thread by Robbie Hatley | last post: by
5 posts views Thread by thermate | last post: by
1 post views Thread by Ioannis Gyftos | last post: by
reply views Thread by jack112 | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.