Re: error LNK2005
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sun, 19 Feb 2006 11:09:06 -0500
You are seeing exactly what should happen. You have made the mistake of declaring
variables in the header file; consequently, each module which includes it gets a new,
conflicting definition of the variable. The first module the linker sees declares the
variable; all subsequent attempts to declare it generate the error you see.
"Assigning values" is a completely unrelated concept to this problem.
Declare the variable once, in the .cpp file associated with the .h file. Declare it as
extern in the header file.
joe
On 17 Feb 2006 09:09:53 -0800, kman_l@xxxxxxxxx wrote:
Can anyone give me some pointers because I get this linking error whichJoseph M. Newcomer [MVP]
does not seem to make sense to me. I have my arrays defined in a
header file and then included the header file in 5 source files. One
source file at the bottom of the chain is Leg.cpp and it does not
complain but all the other files claim that my arrays are already
defined. I don't understand because these other files don't assign the
arrays any values, but does reference these external variables. And
yes I included the header file in all and declared the arrays as
externs.
here is the building print out:
pathpoint.obj : error LNK2005: "char const * * gpcUnit"
(?gpcUnit@@3PAPBDA) already defined in leg.obj
pathpoint.obj : error LNK2005: "char const * * gpcField"
(?gpcField@@3PAPBDA) already defined in leg.obj
datablock.obj : error LNK2005: "char const * * gpcUnit"
(?gpcUnit@@3PAPBDA) already defined in leg.obj
datablock.obj : error LNK2005: "char const * * gpcField"
(?gpcField@@3PAPBDA) already defined in leg.obj
datacontent.obj : error LNK2005: "char const * * gpcUnit"
(?gpcUnit@@3PAPBDA) already defined in leg.obj
datacontent.obj : error LNK2005: "char const * * gpcField"
(?gpcField@@3PAPBDA) already defined in leg.obj
message.obj : error LNK2005: "char const * * gpcUnit"
(?gpcUnit@@3PAPBDA) already defined in leg.obj
message.obj : error LNK2005: "char const * * gpcField"
(?gpcField@@3PAPBDA) already defined in leg.obj
Any help would be very much appreciated.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- error LNK2005
- From: kman_l
- error LNK2005
- Prev by Date: Re: MoveTo / LineTo
- Next by Date: Re: What control is this?
- Previous by thread: Re: error LNK2005
- Next by thread: MoveTo / LineTo
- Index(es):
Relevant Pages
|
|