Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Mat1515

Errors :( Help with "already defined in Main.obj

This topic is 5398 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

Compiling... Main.cpp Linking... Camera.obj : error LNK2005: "void __cdecl KillOpenGL(void)" (?KillOpenGL@@YAXXZ) already defined in Main.obj Camera.obj : error LNK2005: "void __cdecl SetUpGL(void)" (?SetUpGL@@YAXXZ) already defined in Main.obj Camera.obj : error LNK2005: "bool __cdecl SetupPixelFormat(struct HDC__ *)" (?SetupPixelFormat@@YA_NPAUHDC__@@@Z) already defined in Main.obj Camera.obj : error LNK2005: "long __stdcall WndProc(struct HWND__ *,unsigned int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) already defined in Main.obj Camera.obj : error LNK2005: "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ) already defined in Main.obj Camera.obj : error LNK2005: _WinMain@16 already defined in Main.obj Camera.obj : error LNK2005: "struct HGLRC__ * hRC" (?hRC@@3PAUHGLRC__@@A) already defined in Main.obj Camera.obj : error LNK2005: "struct HDC__ * hDC" (?hDC@@3PAUHDC__@@A) already defined in Main.obj Camera.obj : error LNK2005: "struct HWND__ * hwnd" (?hwnd@@3PAUHWND__@@A) already defined in Main.obj Camera.obj : error LNK2005: "struct HINSTANCE__ * hInstance" (?hInstance@@3PAUHINSTANCE__@@A) already defined in Main.obj Camera.obj : error LNK2005: "bool fullscreen" (?fullscreen@@3_NA) already defined in Main.obj Camera.obj : error LNK2005: "class CCamera g_Camera" (?g_Camera@@3VCCamera@@A) already defined in Main.obj Debug/DragRace.exe : fatal error LNK1169: one or more multiply defined symbols found Error executing link.exe.
//GLOBAL DECLARATIONS GO HERE!!!

#ifndef _GLOBALS_H
#define _GLOBALS_H



#include <windows.h>//windows header

#include <gl/gl.h>//gl stuff

#include <gl/glu.h>//gl stuff

#include <gl/glaux.h>//gl stuff


bool	fullscreen;//flag Are we in Fullscreen?


HWND			hwnd = NULL;//handle to window

HINSTANCE		hInstance;//handle  to instance of application

HDC				hDC = NULL;//handle to Device Context

HGLRC			hRC = NULL;//handle to Rendering Context;




//VECTOR CLASS

class CVector3 {
	public:				//Public Access

		float x,y,z;
};

//CAMERA CLASS prototype

class CCamera{	
	public:
		CVector3 m_vPosition;		//Camera Position	

		CVector3 m_vView;			//Camera View

		CVector3 m_vUpVector;		//Up Direction

//m = member Variables 

//Camera Constructor

	CCamera();
	void PositionCamera(float positionX,float positionY,float positionZ,
						float viewX,float viewY,float viewZ,
						float upVectorX, float upVectorY, float upVectorZ);
	void MoveCamera(float speed);
};
						
extern CCamera g_Camera;	//Allows all source files to use this



#endif 
#include "Globals.hpp"

CCamera g_Camera; //our camera!


void KillOpenGL()
{
	//deselect rending context and delete it

	wglMakeCurrent(hDC,NULL);
	wglDeleteContext(hRC);

	//post quit message

	PostQuitMessage(0);
}

void SetUpGL()
{
	glShadeModel(GL_SMOOTH);//smooth colors blending

	
						// Position        View		   Up Vector

	g_Camera.PositionCamera(0, 0.5f, 6,   0, 0.5f, 0,   0, 1, 0); //Camera Start Position!

}

bool SetupPixelFormat(HDC hDC)
{
	int nPixelFormat;

	static PIXELFORMATDESCRIPTOR pfd = {
		sizeof(PIXELFORMATDESCRIPTOR),//always set to this

		1,//version always set to 1

		PFD_DRAW_TO_WINDOW|	//support window

		PFD_SUPPORT_OPENGL|	//support opengl

		PFD_DOUBLEBUFFER,	//support double buffering

		PFD_TYPE_RGBA,	//color mode

		32,	//go for 32 bit color mode

		0,0,0,0,0,0,//ignore color bits, not used

		0,//no alpha buffer

		0,//ignore shift bits

		0,//no accumulation buffer

		0,0,0,0,//ignore accumulation bits

		16,//16-bit Z buffer size

		0,//no stencil buffer

		0,//no auxiliary buffer

		PFD_MAIN_PLANE,//main drawing plane

		0,//reserved

		0,0,0};//layer masks ignored


		//choose best matching pixel format, return index as int

		nPixelFormat = ChoosePixelFormat(hDC,&pfd);

		SetPixelFormat(hDC,nPixelFormat,&pfd);//set it!


		return true;
}


//window message handler

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
	int height, width;//hold window width and height


	switch(message)//switch for sent windows message

	{
	case WM_CREATE://when a window is created

		hDC = GetDC(hwnd);//get the device context for the window pointed to by hwnd

		SetupPixelFormat(hDC);//setup pixel format according to hDC

		//create rendering context and set it as current

		hRC = wglCreateContext(hDC);
		wglMakeCurrent(hDC,hRC);

		return 0;
		break;
	case WM_CLOSE://window closes

		KillOpenGL();//close window

		return 0;
		break;

	case WM_KEYDOWN:

		switch(wParam) 
		{								// Check if we hit a key

			case VK_ESCAPE:
				PostQuitMessage(0);						// Send a QUIT message

				break;
		}
		return 0;
		break;
		
	case WM_SIZE://case window is resized

		height = HIWORD(lParam);//get height from message

		width  = LOWORD(lParam);//get width from message

			
		if(height == 0)//avoid devide by 0

			height = 1;

		//reset the viewport to new dimentions

		glViewport(0,0,width,height);
		glMatrixMode(GL_PROJECTION);//set projection matrix

		glLoadIdentity();//reset projection matrix


		//calculate aspect ratio of window

		gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);

		glMatrixMode(GL_MODELVIEW);//set modelvie matrix

		glLoadIdentity();//load identity Matrix[1,0,0]

											// [0,1,0]

											// [0,0,1]

		return 0;
		break;//break out to switch statement


	default:
		break;
	}

	return (DefWindowProc(hwnd,message,wParam,lParam));//send all unhandled message to windows

}


void RenderScene()
{
	//every.1 = 1 foot

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//clear buffer

	glLoadIdentity();//reset model view matrix


		gluLookAt(g_Camera.m_vPosition.x, g_Camera.m_vPosition.y, g_Camera.m_vPosition.z,	
			  g_Camera.m_vView.x,	  g_Camera.m_vView.y,	  g_Camera.m_vView.z,	
			  g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);

	glTranslatef(0.0f,0.0f,-10.0f);
	glBegin(GL_TRIANGLES);
		glColor3f(1.0f,0.0f,0.0f);
		glVertex3f(0.0f,1.0f,0.0f);
		glVertex3f(-1.0f,0.0f,0.0f);
		glVertex3f(1.0f,0.0f,0.0f);				
	glEnd();
}

//the main entry point

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
	WNDCLASSEX ws;//window class

	MSG msg; //message

	bool done;  //flag saying when we are done


	//class structure

	ws.cbClsExtra = 0;//nothing extra

	ws.cbSize = sizeof(WNDCLASSEX);//always set to this

	ws.cbWndExtra = 0;//nothing extra

	ws.hbrBackground = NULL;//no need for a backgound

	ws.hCursor = LoadCursor(NULL, IDC_ARROW);//default cursor

	ws.hIcon = NULL;//no icon

	ws.hIconSm = NULL;//no tray icon

	ws.hInstance = hInstance;//instance of APP

	ws.lpfnWndProc = WndProc;//message handler for window

	ws.lpszClassName = "My Class";//class name

	ws.lpszMenuName = NULL;//no menu

	ws.style = CS_HREDRAW|CS_VREDRAW;//when resized redraw screen


	//register the class

	if(!RegisterClassEx(&ws))
	{
		MessageBox(NULL,"ERROR","Unable To Register Class!",MB_OK);
		return 0;//fails registering exit

	}

	//create window

	hwnd = CreateWindowEx(NULL,//extended style

		"My Class",//class name

		"Matt Janas",//app name

		WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_SYSMENU|
		WS_CLIPCHILDREN|
		WS_CLIPSIBLINGS,//style don''t draw unseen parts of windows

		100,100,//x,y

		800,600,//width height

		NULL,//handle to parent

		NULL,//handle to menu

		hInstance,//app instance

		NULL);//no extra params


	//check to see if window was created

	if(!hwnd)
	{
		MessageBox(NULL,"ERROR","Unable To Create Window!",MB_OK);
		return 0; //quit

	}

	ShowWindow(hwnd,SW_SHOW);//display window

	UpdateWindow(hwnd);//update window


	SetUpGL();//go to set up GL

	
			
	done = false;//flag to start main loop


	//main message loop

	while(!done)
	{
		PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);//check for messages


		if(msg.message == WM_QUIT)//if there is a QUIT message

			done = true;//end APP

		else
		{//rendering in here!

			
			RenderScene();//draw stuff


			
			SwapBuffers(hDC);//swap buffer Back to Front

		}
		TranslateMessage(&msg);
		DispatchMessage(&msg); //translate and dispatch to event queue

	}

	return msg.wParam;
}
#include "main.cpp"

//Camera Class Definitions


//Constructor


CCamera::CCamera()
{
	CVector3 vView = {0.0,0.0,0.0}; //Starting Point Camera Postion

	CVector3 vZero = {0.0,1.0,0.5};	//Look to

	CVector3 vUp   = {0.0,0.0,1.0};	//UpVector


	m_vPosition = vZero;
	m_vView		= vView;
	m_vUpVector	= vUp;
}

GLvoid CCamera::PositionCamera(float positionX,float positionY,float positionZ,
							   float viewX,float viewY,float viewZ,
							   float upVectorX,float upVectorY,float upVectorZ)
{
	CVector3 vPosition	= {positionX, positionY, positionZ};
	CVector3 vView		= {viewX, viewY, viewZ};
	CVector3 vUpVector	= {upVectorX, upVectorY, upVectorZ};

	m_vPosition = vPosition;					// Assign the position

	m_vView = vView;							// Assign the view

	m_vUpVector = vUpVector;					// Assign the up vector


}

void CCamera::MoveCamera(float speed)
{
	CVector3 vVector = {0};

	//V = v - p (Get direction were facing!)

	vVector.x = m_vView.x - m_vPosition.x; //Get x direction

	vVector.y = m_vView.y - m_vPosition.y; //get y direction

	vVector.z = m_vView.z - m_vPosition.z;	//get z direction


	m_vPosition.x += vVector.x * speed;		// Add our acceleration to our position''s X

	m_vPosition.z += vVector.z * speed;		// Add our acceleration to our position''s Z

	m_vView.x += vVector.x * speed;			// Add our acceleration to our view''s X

	m_vView.z += vVector.z * speed;			// Add our acceleration to our view''s Z

}

Share this post


Link to post
Share on other sites
Advertisement
Why are you including a CPP file anywhere? The purpose of header files is to provide an interface between translation units. Learn how to properly use multiple files.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!