By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,187 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.