Error LNK2005

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Error LNK2005

Post by thejahooli »

When I try to build my project in Visual c++ it comes up with this:

1>Game.obj : error LNK2005: "bool gameend" (?gameend@@3_NA) already defined in DisplayGrid.obj

repeated 226 times with different variables

I have looked up on google how to fix it but I do not understand most of them as I am quite new to programming. If anyone could tell me how to fix this in a way that someone quite new to programming would understand.
I'll make your software hardware.
User avatar
Spikey
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 98
Joined: Sat Dec 13, 2008 6:39 am
Programming Language of Choice: C++
Location: Ottawa, Canada
Contact:

Re: Error LNK2005

Post by Spikey »

Welcome to linker hell! :twisted:
Says your defining something that already exists. The easy way is to add #pragma to the first line in all your headers. Or you can wrap your headers like this for non-window machines:

Code: Select all

#ifndef _SOMETHING_UNIQUE_
#define _SOMETIHNG_UNIQUE_

(code)

#endif
If that doesn't help, then you might have to check your #includes, make sure they're executed in the right order.
Basically the pre-processors ( keywords with # ) will make sure headers are only defined once.
Hope it works, showing code helps diagnose problems alot more too.
User avatar
sparda
Chaos Rift Junior
Chaos Rift Junior
Posts: 291
Joined: Tue Sep 23, 2008 3:54 pm

Re: Error LNK2005

Post by sparda »

If you're only going to use VC++ then you can also try a single line of code that would be equivalent to the above #ifndef wrapper guards:

Code: Select all

#pragma once
Post Reply