Error with 'multiple definition'

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
#include
#include
#include
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/

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 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
#include
#include
#include
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

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” 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 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
#include
#include
#include
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

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.

-WillOn 2/13/07, Lilith Calbridge 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” <@William_Langford> 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 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
#include
#include
#include
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

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 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 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 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
#include
#include
#include
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

Heh.

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

-WillOn 2/13/07, Patrick Mohr 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 < @William_Langford> 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 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” < @William_Langford> 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
#include
#include
#include
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