[Solved]Visual Studio Linker Error

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
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

[Solved]Visual Studio Linker Error

Post by hurstshifter »

Hey Guys,

So I recently started putting together a new project in Visual Studio 2008. I am getting a linker error when I try to build telling me that some of my globals are already defined. I've used this same process before but for some reason it doesn't seem to be working any more. Here is the error...

Code: Select all

 error LNK2005: "struct SDL_Surface * screen" (?screen@@3PAUSDL_Surface@@A) already defined in functions.obj
error LNK2005: "union SDL_Event event" (?event@@3TSDL_Event@@A) already defined in functions.obj
error LNK2005: "class Timer timer1" (?timer1@@3VTimer@@A) already defined in functions.obj
error LNK2005: "struct SDL_Surface * screen" (?screen@@3PAUSDL_Surface@@A) already defined in functions.obj
error LNK2005: "union SDL_Event event" (?event@@3TSDL_Event@@A) already defined in functions.obj
error LNK2005: "class Timer timer1" (?timer1@@3VTimer@@A) already defined in functions.obj
error LNK2005: "struct SDL_Surface * screen" (?screen@@3PAUSDL_Surface@@A) already defined in functions.obj
error LNK2005: "union SDL_Event event" (?event@@3TSDL_Event@@A) already defined in functions.obj
error LNK2005: "class Timer timer1" (?timer1@@3VTimer@@A) already defined in functions.obj

All referencing items in my globals.h file. A timer class, screen surface, and event structure. I recently switched from Visual c++ Express to Visual Studio 2008 Professional so I'm not sure if maybe my project options are causing this. I'm guessing not though. I must have something coded wrong. At first I thought I might have my #ifndefs setup wrong but each header file has them. Any thoughts?
Last edited by hurstshifter on Sat Aug 01, 2009 1:56 pm, edited 1 time in total.
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: Visual Studio Linker Error

Post by qpHalcy0n »

1) If it worked in VS express, you may simply have a bad build. Have you tried cleaning and rebuilding? (Right click on the project...hit rebuild).

2) You may have actually multiply defined everything in that file. This is usually the case when you have mutual inclusion. Eg: crap.h includes stuff.h, and stuff.h includes crap.h
if: you have the includes within the file guards (#ifndef) then the includes become part of the definition and if were linked first will result in being multiply defined. solution: if the
file being included is a common file (eg: one that can conceivably be used all over), put it outside of your file definition (outside of your #ifdef/#define pair).
User avatar
hurstshifter
ES Beta Backer
ES Beta Backer
Posts: 713
Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:

Re: [Solved]Visual Studio Linker Error

Post by hurstshifter »

Figured it out, thanks. :)
"Time is an illusion. Lunchtime, doubly so."
http://www.thenerdnight.com
Post Reply