Page 1 of 1

[Solved]Visual Studio Linker Error

Posted: Sat Aug 01, 2009 11:53 am
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?

Re: Visual Studio Linker Error

Posted: Sat Aug 01, 2009 12:16 pm
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).

Re: [Solved]Visual Studio Linker Error

Posted: Sat Aug 01, 2009 1:57 pm
by hurstshifter
Figured it out, thanks. :)