[SDL] error with 'multiple definition'

Will Langford unfies at gmail.com
Tue Feb 13 15:35:46 PST 2007


Heh.

Giving the answer rather than making them figure it out, pfft :)

-Will


On 2/13/07, Patrick Mohr <kc7zzv at gmail.com> wrote:
>
> I think that the way around this is to change
>
> std::string rem = "//";
>
> to
>
> extern std::string rem;
>
> and then put
>
> std::string rem = "//";
>
> inside of a .cpp file.
> Baiscly, what that does is declare the variable in the .h and define is in
> the .cpp.  That way every file that includes the header knows that there is
> a variable called reb but only the .cpp file will create it.  That should
> fix your link errors.
>
> On 2/13/07, Will Langford < unfies at gmail.com> wrote:
>
> > No, he's trapped multiple declarations within each object. So each
> > object is guarunteed to have A.h ooeygooey goodness only once.  If he's
> > compiling with multiple .c files that include A.h, then each one will
> > have a 'rem'.
> >
> > When you link the multiple objects together, the linker will see each
> > 'rem' and get confused.
> >
> > -Will
> >
> >
> > On 2/13/07, Lilith Calbridge <lilith at dcccd.edu> wrote:
> > >
> > > But he's trapped subsequent declarations.  On the first pass it checks
> > > to see if A_H is defined.  If not, it defines it.  The remainder is enclosed
> > > within the conditional.  On a second pass it should find that A_H is defined
> > > and thus will skip everything up to the #endif.
> > >
> > > The only other thing I can think of, except for the compiler not
> > > working properly, is that rem is declared somewhere else in the program.
> > >
> > > Lilith
> > >
> > > >>> On 2/13/2007 at 3:38 PM, "Will Langford" < unfies at gmail.com>
> > > wrote:
> > > > If more than one file #include's A.H, each one will attempt to
> > > declare
> > > > std::string rem.  Fine during compiling, but when it comes time to
> > > link, the
> > > > linker will see multiple things with the same name.
> > > >
> > > >
> > > > On 2/13/07, nathayan de los valles < semiogro at hotmail.com> wrote:
> > > >>
> > > >> Hi all,
> > > >> Perhaps this is not the best place to throw my doubt... but I have
> > > no
> > > >> friends who can answer me.
> > > >> I am using C++ and SDL.
> > > >> I have several files .h like this:
> > > >> A.h
> > > >> #ifndef A_H
> > > >> #define A_H
> > > >> #include <iostream>
> > > >> #include <sstream>
> > > >> #include <string>
> > > >> #include <fstream>
> > > >> std::string rem = "//";
> > > >> //more definitions
> > > >> #endif
> > > >>
> > > >> B.h
> > > >> #ifndef B_H
> > > >> #define B_H
> > > >> #include "A.h"
> > > >> //definitions
> > > >> #endif
> > > >>
> > > >> My compiler says me:   multiple definition of 'rem'. I think my
> > > compiler
> > > >> doesn't run properly. Any idea?
> > > >>
> > > >> I use:
> > > >> Dev C++ 4.9.9.2 (I know there is more interesting information but I
> > > don't
> > > >> remember where to find it).
> > > >> Thanks in advance.
> > > >>
> > > >> _________________________________________________________________
> > > >> Horóscopo, tarot, numerología... Escucha lo que te dicen los
> > > astros.
> > > >> http://astrocentro.msn.es/
> > > >>
> > > >> _______________________________________________
> > > >> SDL mailing list
> > > >> SDL at lists.libsdl.org
> > > >> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> > > >>
> > >
> > > _______________________________________________
> > > SDL mailing list
> > > SDL at lists.libsdl.org
> > > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> > >
> >
> >
> > _______________________________________________
> > SDL mailing list
> > SDL at lists.libsdl.org
> > http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
> >
> >
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070213/03d44ee9/attachment.html 


More information about the SDL mailing list