• Advertisement
Sign in to follow this  

Annoying Error

This topic is 3352 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I am getting an error, I know what's supposed to be causing it, a global declared in a header/including a header several times but I can't find any instances of this in my code... any other reason why it would be giving me this errors? 1>Linking... 1>WinMain.obj : error LNK2005: "public: __thiscall Application::Application(int,int)" (??0Application@@QAE@HH@Z) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: struct HWND__ * __thiscall Application::get_handle(void)const " (?get_handle@Application@@QBEPAUHWND__@@XZ) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: struct Coord __thiscall Application::get_dimensions(void)const " (?get_dimensions@Application@@QBE?AUCoord@@XZ) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: struct Input __thiscall Application::get_input_data(void)const " (?get_input_data@Application@@QBE?AUInput@@XZ) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: bool __thiscall Application::display_window(struct HINSTANCE__ *,int)" (?display_window@Application@@QAE_NPAUHINSTANCE__@@H@Z) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: bool __thiscall Application::handle_messages(void)" (?handle_messages@Application@@QAE_NXZ) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: static long __stdcall Application::FilterWndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?FilterWndProc@Application@@SGJPAUHWND__@@IIJ@Z) already defined in Loop.obj 1>WinMain.obj : error LNK2005: "public: long __stdcall Application::WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@Application@@QAGJPAUHWND__@@IIJ@Z) already defined in Loop.obj 1>C:\Documents and Settings\David\Mis documentos\Visual Studio 2005\Projects\Dungeon\Debug\Dungeon.exe : fatal error LNK1169: one or more multiply defined symbols found 1>Build log was saved at "file://c:\Documents and Settings\David\Mis documentos\Visual Studio 2005\Projects\Dungeon\Dungeon\Debug\BuildLog.htm" 1>Dungeon - 9 error(s), 4 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Here's is the code involved, it tells me functions from the winmain.h have been defined already in the loop.obj which I suppose is either the header or the source file.. winmain source file
#include <windows.h>
#include <windowsx.h>
#include "winmain.h"
#include "direct3d.h"
#include "loop.h"

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
	//Display Window
	Application application(640,480);
	if(!application.display_window(hInstance, nCmdShow))
		return 0;

	//Init D3D
	Direct3D direct3d;
	if(!direct3d.init_d3d(application.get_handle(), application.get_dimensions()))
		return 0;

/*	sprite ship;
	sprite missile;

	load_graphics();*/

	main_loop(application);

    direct3d.close_directx();

    return 0;
}

winmain header
#ifndef WIN_MAIN_H
#define WIN_MAIN_H

#include <windows.h>
#include <windowsx.h>
#include "coord.h"
#include "input.h"

class Application
{
private:
	HWND hWnd;
	Coord dimensions;
	Input input_data;

public:

	Application(int,int);
	HWND get_handle() const;
	Coord get_dimensions() const;
	Input get_input_data() const;
	bool display_window(HINSTANCE, int);
	bool handle_messages();
	static LRESULT CALLBACK FilterWndProc(HWND, UINT, WPARAM, LPARAM);
	LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
};

Application::Application(int x, int y)
:
dimensions(x,y)
{}

HWND Application::get_handle() const
{
	return hWnd;
}

Coord Application::get_dimensions() const
{
	return dimensions;
}

Input Application::get_input_data() const
{
	return input_data;
}

bool Application::display_window(HINSTANCE hInstance, int nCmdShow)
{	
	//Register Window
	const LPCSTR className = "WindowClass1";

	WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = FilterWndProc;
	wc.hInstance = hInstance;
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.lpszClassName = className;

    if(RegisterClassEx(&wc)==0)
		return FALSE;

	//Create Window
	const LPCSTR windowName = "Dungeon";
	const DWORD windowStyle = WS_OVERLAPPEDWINDOW;

    hWnd = CreateWindowEx(NULL,
                          className,
                          windowName,
						  windowStyle,
                          0, 0,
                          dimensions.x,
						  dimensions.y,
                          NULL,
                          NULL,
                          hInstance,
                          this);

	if(hWnd == NULL)
		return FALSE;

	//Show Window
    ShowWindow(hWnd, nCmdShow);

	return TRUE;
}

bool Application::handle_messages()
{
	static MSG msg;

	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		if(msg.message == WM_QUIT)
			return FALSE;

		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return TRUE;
}

LRESULT CALLBACK Application::FilterWndProc(HWND hWnd, UINT message,
													  WPARAM wParam, LPARAM lParam)
{
    if (message == WM_CREATE) 
	{
        SetWindowLongPtr(hWnd, GWLP_USERDATA,
                         reinterpret_cast<LONG_PTR>(
                            reinterpret_cast<CREATESTRUCT *>(lParam)->
                                lpCreateParams));
    }
    
    Application *self = reinterpret_cast<Application *>(
        GetWindowLongPtr(hWnd, GWLP_USERDATA));

    if (self != 0)
        return self->WndProc(hWnd, message, wParam, lParam);

    return DefWindowProc(hWnd, message, wParam, lParam); 
}

LRESULT CALLBACK Application::WndProc(HWND hWnd, UINT message,
											   WPARAM wParam, LPARAM lParam)
{
    switch(message)
	{
        case WM_DESTROY:
			{
                PostQuitMessage(0);
                return 0;
            } break;

		case WM_KEYDOWN:
			{
				switch(wParam)
				{
				case VK_RIGHT:
					{
						input_data.turn_right = true;
					} break;
					
				case VK_LEFT:
					{
						input_data.turn_left = true;
					} break;

				case VK_UP:
					{
						input_data.move_forward = true;
					} break;

				case VK_DOWN:
					{
						input_data.move_backward = true;
					} break;

				case VK_SPACE:
					{
						input_data.shooting = true;
					} break;

				case VK_ESCAPE:
					{
						DestroyWindow(hWnd);
					} break;

				}

			} break;

		case WM_KEYUP:
			{
				switch(wParam)
				{
				case VK_RIGHT:
					{
						input_data.turn_right = false;
					} break;
					
				case VK_LEFT:
					{
						input_data.turn_left = false;
					} break;

				case VK_UP:
					{
						input_data.move_forward = false;
					} break;

				case VK_DOWN:
					{
						input_data.move_backward = false;
					} break;

				case VK_SPACE:
					{
						input_data.shooting = false;
					} break;
				}

			} break;
	}

    return DefWindowProc (hWnd, message, wParam, lParam);
}

#endif

loop source
#include "loop.h"
#include "winmain.h"
#include "input.h"
#include <vector>

void main_loop(Application application)
{
	Input input_data = application.get_input_data();
//	std::vector<Object> game_objects;
//	init_game(&game_objects);

	while(application.handle_messages())
	{
//		update(&game_objects, input_data);
//		render(&game_objects);
	}
}

loop header
#ifndef LOOP_H
#define LOOP_H

#include "winmain.h"

void main_loop(Application);

#endif

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement