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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Robbie Hatley

    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



  • Victor Bazarov

    #2
    Re: Template "redefinit ion" linker error. (attempt #2)

    Robbie Hatley wrote:[color=blue]
    > [...]
    > 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 [...][/color]

    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


    Comment

    Working...