[SOLVED] Help with Declaration Problem

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

User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Help with Declaration Problem

Post by xiphirx »

Ok, I believe I have forward declared correctly, and it compiles fine now, but I have 48 LNK2005 errors...

Code: Select all

1>map.obj : error LNK2005: "struct SDL_Surface * __cdecl loadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadImage@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
1>map.obj : error LNK2005: "void __cdecl applySurface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (?applySurface@@YAXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z) already defined in main.obj
1>map.obj : error LNK2005: "unsigned int __cdecl get_pixel32(struct SDL_Surface *,int,int)" (?get_pixel32@@YAIPAUSDL_Surface@@HH@Z) already defined in main.obj
1>map.obj : error LNK2005: "void __cdecl put_pixel32(struct SDL_Surface *,int,int,unsigned int)" (?put_pixel32@@YAXPAUSDL_Surface@@HHI@Z) already defined in main.obj
1>map.obj : error LNK2005: "void __cdecl flip_surface(struct SDL_Surface *,int,int)" (?flip_surface@@YAXPAUSDL_Surface@@HH@Z) already defined in main.obj
1>map.obj : error LNK2005: "void __cdecl rotate_surface(struct SDL_Surface *,int,struct SDL_Rect *)" (?rotate_surface@@YAXPAUSDL_Surface@@HPAUSDL_Rect@@@Z) already defined in main.obj
1>map.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl openFileName(char *,struct HWND__ *)" (?openFileName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADPAUHWND__@@@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "struct SDL_Surface * __cdecl loadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadImage@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "void __cdecl applySurface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (?applySurface@@YAXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "unsigned int __cdecl get_pixel32(struct SDL_Surface *,int,int)" (?get_pixel32@@YAIPAUSDL_Surface@@HH@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "void __cdecl put_pixel32(struct SDL_Surface *,int,int,unsigned int)" (?put_pixel32@@YAXPAUSDL_Surface@@HHI@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "void __cdecl flip_surface(struct SDL_Surface *,int,int)" (?flip_surface@@YAXPAUSDL_Surface@@HH@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "void __cdecl rotate_surface(struct SDL_Surface *,int,struct SDL_Rect *)" (?rotate_surface@@YAXPAUSDL_Surface@@HPAUSDL_Rect@@@Z) already defined in main.obj
1>mapEditor.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl openFileName(char *,struct HWND__ *)" (?openFileName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADPAUHWND__@@@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "struct SDL_Surface * __cdecl loadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadImage@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "void __cdecl applySurface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (?applySurface@@YAXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "unsigned int __cdecl get_pixel32(struct SDL_Surface *,int,int)" (?get_pixel32@@YAIPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "void __cdecl put_pixel32(struct SDL_Surface *,int,int,unsigned int)" (?put_pixel32@@YAXPAUSDL_Surface@@HHI@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "void __cdecl flip_surface(struct SDL_Surface *,int,int)" (?flip_surface@@YAXPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "void __cdecl rotate_surface(struct SDL_Surface *,int,struct SDL_Rect *)" (?rotate_surface@@YAXPAUSDL_Surface@@HPAUSDL_Rect@@@Z) already defined in main.obj
1>xi_button.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl openFileName(char *,struct HWND__ *)" (?openFileName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADPAUHWND__@@@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "struct SDL_Surface * __cdecl loadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadImage@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "void __cdecl applySurface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (?applySurface@@YAXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "unsigned int __cdecl get_pixel32(struct SDL_Surface *,int,int)" (?get_pixel32@@YAIPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "void __cdecl put_pixel32(struct SDL_Surface *,int,int,unsigned int)" (?put_pixel32@@YAXPAUSDL_Surface@@HHI@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "void __cdecl flip_surface(struct SDL_Surface *,int,int)" (?flip_surface@@YAXPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "void __cdecl rotate_surface(struct SDL_Surface *,int,struct SDL_Rect *)" (?rotate_surface@@YAXPAUSDL_Surface@@HPAUSDL_Rect@@@Z) already defined in main.obj
1>xi_buttonbase.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl openFileName(char *,struct HWND__ *)" (?openFileName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADPAUHWND__@@@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "struct SDL_Surface * __cdecl loadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadImage@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "void __cdecl applySurface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (?applySurface@@YAXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "unsigned int __cdecl get_pixel32(struct SDL_Surface *,int,int)" (?get_pixel32@@YAIPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "void __cdecl put_pixel32(struct SDL_Surface *,int,int,unsigned int)" (?put_pixel32@@YAXPAUSDL_Surface@@HHI@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "void __cdecl flip_surface(struct SDL_Surface *,int,int)" (?flip_surface@@YAXPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "void __cdecl rotate_surface(struct SDL_Surface *,int,struct SDL_Rect *)" (?rotate_surface@@YAXPAUSDL_Surface@@HPAUSDL_Rect@@@Z) already defined in main.obj
1>xi_label.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl openFileName(char *,struct HWND__ *)" (?openFileName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADPAUHWND__@@@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "struct SDL_Surface * __cdecl loadImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?loadImage@@YAPAUSDL_Surface@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "void __cdecl applySurface(int,int,struct SDL_Surface *,struct SDL_Surface *,struct SDL_Rect *)" (?applySurface@@YAXHHPAUSDL_Surface@@0PAUSDL_Rect@@@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "unsigned int __cdecl get_pixel32(struct SDL_Surface *,int,int)" (?get_pixel32@@YAIPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "void __cdecl put_pixel32(struct SDL_Surface *,int,int,unsigned int)" (?put_pixel32@@YAXPAUSDL_Surface@@HHI@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "void __cdecl flip_surface(struct SDL_Surface *,int,int)" (?flip_surface@@YAXPAUSDL_Surface@@HH@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "void __cdecl rotate_surface(struct SDL_Surface *,int,struct SDL_Rect *)" (?rotate_surface@@YAXPAUSDL_Surface@@HPAUSDL_Rect@@@Z) already defined in main.obj
1>xi_window.obj : error LNK2005: "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl openFileName(char *,struct HWND__ *)" (?openFileName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PADPAUHWND__@@@Z) already defined in main.obj
1>C:\Users\Xiphirx\Documents\CSPSPMEP Dev\CSPSPMEPv2\Debug\CSPSPMEPv2.exe : fatal error LNK1169: one or more multiply defined symbols found
I have been trying to figure this out for a good 2 hours now... I am willing to zip my source code up if anyone is willing to look at it D: I don't think I can paste it all here, but somethings of interest (I assume) are below:

main.cpp

Code: Select all

#include <iostream>
#include "SDL.h"
#include "mapEditor.h"

using namespace std;

int main( int argc, char* args[] ) 
{
	mapEditor Editor(800, 600, 32, 60);
	return Editor.loop();
}
mapEditor.h

Code: Select all

#ifndef MAPEDITOR
#define MAPEDITOR
#include <sstream>
#include "Timer.h"
#include "resourceManager.h"
#include "map.h"
#include "xi_window.h"

using namespace std;

class mapEditor
{
public:
	mapEditor(int width, int height, int bbp, int fps = 60);
	~mapEditor();

	//Accessors
	SDL_Surface * getScreen();

	//Modifiers
	void newMap(string path);

	//other
	int loop();

private:
	//Screen surface, everything is drawn to it
	SDL_Surface* screen;
	SDL_Surface* backgroundFill;
	SDL_Surface* tileSelector;
	
	//Screen variables
	int SCREENWIDTH,
		SCREENHEIGHT,
		SCREENBBP,
		FPS;
	
	//FPS Control
	int frame;

	//GUI data
	int currentMap,
		totalMaps;

	//Events from keyboard
	char key[323];

	//Events
	SDL_Event editorEvents;

	//Program flow
	bool quit;

	//Timers
	Timer FPSControl;

	//Resource manager
	resourceManager resources;

	//maps
	vector<map> maps;

	//windowstest
	xiGUI::window functionBar, infoBar;

	//fonts
	TTF_Font * editorFont;

	//string stream for misc use
	ostringstream stringStream;
};
#endif
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Help with Declaration Problem

Post by dandymcgee »

Do all of your headers have include protection? It looks like something is being included twice (judging by the fact that all of the linker errors end with "is already defined in main.obj").
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Help with Declaration Problem

Post by xiphirx »

dandymcgee wrote:Do all of your headers have include protection? It looks like something is being included twice (judging by the fact that all of the linker errors end with "is already defined in main.obj").
yes they do

EDIT: got it down to 29 somehow D8
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Help with Declaration Problem

Post by MrDeathNote »

xiphirx wrote:
dandymcgee wrote:Do all of your headers have include protection? It looks like something is being included twice (judging by the fact that all of the linker errors end with "is already defined in main.obj").
yes they do

EDIT: got it down to 29 somehow D8
Where else are you including SDL.h? And theres no forward decalration in mapEditor.h just a bunch of includes.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
xiphirx
Chaos Rift Junior
Chaos Rift Junior
Posts: 324
Joined: Mon Mar 22, 2010 3:15 pm
Current Project: ******** (Unkown for the time being)
Favorite Gaming Platforms: PC
Programming Language of Choice: C++
Contact:

Re: Help with Declaration Problem

Post by xiphirx »

I've fixed this problem a few days ago lol, didn't mark the topic sorry.

Anyway I am a dumbass (as usual) and I was thinking headers were something they weren't :) Everything is fine now.
StarCraft II Zerg Strategy, open to all levels of players!

Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of :)
Post Reply