www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - Previous definition different errror

reply "chris elliott" <biol75 york.ac.uk> writes:
I have a header file for my wxhatch application, which contains a collection
of lines like this

const wxString space = wxT(' ');

which are used in several code .cpp files.

On linking the files I get errors

 Error 1: Previous Definition Different : ?space  3VwxString  B (const
wxString space)

My compile and link lines are

dmc -c -o -mn -W -H -D__NT__ -DWIN32 -D__WIN32__ -D__WIN95__ -D__WINDOWS__ -
D__W
XMSW__ -D__SC__ -D__WXDEBUG__  -I..\..\wxWindows\include -I..\..\wxWindows\l
ib\_
sc -I..\..\wxWindows\contrib\include -I..\..\wxWindows/src/regex;..\..\wxWin
dows
/src/png;..\..\wxWindows/src/jpeg;..\..\wxWindows/src/zlib;..\..\wxWindows/s
rc/t
iff  wxhatch.cpp -owxhatch.obj

.... more lines all the same


link  /DELEXECUTABLE /RC -L/exet:nt/su:windows wxhatch.obj wxhcombo.obj
bitmenu.
obj mcanvas.obj mytext.obj tchild.obj trchild.obj lchild.obj mchild.obj
raddlg.o
bj textdlg.obj startdlg.obj srdlg.obj mnudlg.obj cfgdlg.obj tooldlg.obj
mcdlg.ob
j , wxhatch.exe, wxhatch, ..\..\wxWindows\lib\ wx_sc.lib
..\..\wxWindows\lib\stc
_sc.lib png_sc tiff_sc jpeg_sc zlib_sc shell32_sc wsock32_sc advapi32
comctl32 c
omdlg32 ctl3d32 gc  gdi32 kernel32 ole32 oleaut32 snn user32 uuid
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

bitmenu.obj(bitmenu)  Offset 000B1H Record Type 0091
 Error 1: Previous Definition Different : ?wxH_VersionString  3VwxString  B
(con
st wxString wxH_VersionString)


thanks
chris
Jun 17 2003
parent reply "Walter" <walter digitalmars.com> writes:
"chris elliott" <biol75 york.ac.uk> wrote in message
news:bcmojg$q29$1 digitaldaemon.com...
 I have a header file for my wxhatch application, which contains a
collection
 of lines like this

 const wxString space = wxT(' ');

 which are used in several code .cpp files.

 On linking the files I get errors

  Error 1: Previous Definition Different : ?space  3VwxString  B (const
 wxString space)
Move the line in the header to a .cpp file. Replace the line in the header with: extern const wxString space;
Jun 17 2003
parent reply "chris elliott" <chris ampleforth.u-net.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bcnd45$1cs2$1 digitaldaemon.com...
 "chris elliott" <biol75 york.ac.uk> wrote in message
 news:bcmojg$q29$1 digitaldaemon.com...
 I have a header file for my wxhatch application, which contains a
collection
 of lines like this

 const wxString space = wxT(' ');

 which are used in several code .cpp files.

 On linking the files I get errors

  Error 1: Previous Definition Different : ?space  3VwxString  B (const
 wxString space)
Move the line in the header to a .cpp file. Replace the line in the header with: extern const wxString space;
That worked fine, So is this a bug in DM or a "feature" of the other compilers? chris
Jun 17 2003
next sibling parent reply "Wichetael" <wichetael gmx.net> writes:
It's more of a 'feature' of other compilers. In essence by *defining* the
constant in the header file you *define* it multiple times as the header is
included in multiple objects, (as in files, not in OO instances.) Strictly
speaking this is not allowed by the standard, (at least afaik,) and what you
should do instead, (as Walter suggested,) is *declare* the constant in the
header file, but *define* it in a source file so that it is included in only
one object. Some compilers simply silently ignore multiple definitions and
drop all the definitions that come after the first one. But that is of
course a non-standard approach and it is ill advised to rely on this if you
want your code to be portable.

btw, Walter, why does the compiler report that the previous definition is
different? Shouldn't it report that it is a multiple definition since the
definitions are actually the same?

Hope I got all my terms ans stuff right ;)

Regards, Remko van der Vossen.

"chris elliott" <chris ampleforth.u-net.com> wrote in message
news:bcnl2i$1kl8$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:bcnd45$1cs2$1 digitaldaemon.com...
 "chris elliott" <biol75 york.ac.uk> wrote in message
 news:bcmojg$q29$1 digitaldaemon.com...
 I have a header file for my wxhatch application, which contains a
collection
 of lines like this

 const wxString space = wxT(' ');

 which are used in several code .cpp files.

 On linking the files I get errors

  Error 1: Previous Definition Different : ?space  3VwxString  B (const
 wxString space)
Move the line in the header to a .cpp file. Replace the line in the
header
 with:

     extern const wxString space;
That worked fine, So is this a bug in DM or a "feature" of the other compilers? chris
Jun 17 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Wichetael" <wichetael gmx.net> wrote in message
news:bcnn06$1mat$1 digitaldaemon.com...
 btw, Walter, why does the compiler report that the previous definition is
 different? Shouldn't it report that it is a multiple definition since the
 definitions are actually the same?
Yes, that would be better.
Jun 17 2003
parent "chris elliott" <chris ampleforth.u-net.com> writes:
yes, I would live with it if it said the definitons were the same....
Different definitons made me think it was a linker bug

chris
"Walter" <walter digitalmars.com> wrote in message
news:bcnpjg$1p52$2 digitaldaemon.com...
 "Wichetael" <wichetael gmx.net> wrote in message
 news:bcnn06$1mat$1 digitaldaemon.com...
 btw, Walter, why does the compiler report that the previous definition
is
 different? Shouldn't it report that it is a multiple definition since
the
 definitions are actually the same?
Yes, that would be better.
Jun 17 2003
prev sibling parent "Walter" <walter digitalmars.com> writes:
"chris elliott" <chris ampleforth.u-net.com> wrote in message
news:bcnl2i$1kl8$1 digitaldaemon.com...
 That worked fine,
 So is this a bug in DM or a "feature" of the other compilers?
The way DM works is the way the language is defined to work. You might be seeing an extension done by other compilers.
Jun 17 2003