Archived

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

SSJCORY

Help with linking error.

Recommended Posts

I tried to make a file with functions to initialize d3d and uninitialize it but when i did that i got these errors:
--------------------Configuration: BULLSHIT - Win32 Debug--------------------
Compiling...
D3DShit.cpp
Skipping... (no relevant changes detected)
win.cpp
Linking...
D3DShit.obj : error LNK2005: "void __cdecl InitMyD3D(struct HWND__ *,bool,int,int)" (?InitMyD3D@@YAXPAUHWND__@@_NHH@Z) already defined in win.obj
D3DShit.obj : error LNK2005: "void __cdecl KillMyD3D(void)" (?KillMyD3D@@YAXXZ) already defined in win.obj
D3DShit.obj : error LNK2005: "struct IDirect3DDevice8 * pd3dd" (?pd3dd@@3PAUIDirect3DDevice8@@A) already defined in win.obj
D3DShit.obj : error LNK2005: "struct IDirect3D8 * pd3d" (?pd3d@@3PAUIDirect3D8@@A) already defined in win.obj
Debug/BULLSHIT.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

BULLSHIT.exe - 5 error(s), 0 warning(s)
Here is the code in my D3D init file:
//D3DShit.cpp

#include<d3d8.h>
#include<d3dx8.h>
#pragma comment(lib,"d3d8.lib")
#pragma comment(lib,"d3dx8.lib")
LPDIRECT3D8 pd3d;
IDirect3DDevice8 *pd3dd;
void InitMyD3D(HWND hWnd,bool full,int width,int height){
	D3DPRESENT_PARAMETERS d3dpp;
	D3DDISPLAYMODE d3ddm;
	pd3d = Direct3DCreate8(D3D_SDK_VERSION);
	pd3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm);
	ZeroMemory(&d3dpp,sizeof(d3dpp));
	d3dpp.BackBufferCount = 1;
	d3dpp.hDeviceWindow = hWnd;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	if(full){
		d3dpp.BackBufferWidth = width;
		d3dpp.BackBufferHeight = height;
		d3dpp.BackBufferFormat = D3DFMT_R5G6B5;
		d3dpp.Windowed = FALSE;
	}
	else{
		d3dpp.BackBufferFormat = d3ddm.Format;
		d3dpp.Windowed = TRUE;
	}
	pd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pd3dd);
	pd3dd->SetRenderState(D3DRS_LIGHTING,FALSE);
}
void KillMyD3D(){
	if(pd3d != NULL){
		pd3d->Release();
		pd3d = NULL;
	}
	if(pd3dd != NULL){
		pd3dd->Release();
		pd3dd = NULL;
	}
}
and here is when i try to use it:
//win.cpp

#include<windows.h>
#include"D3DShit.cpp"
bool gameover = false;
bool fullscreen = true;
int gwidth = 640;
int gheight = 480;
HINSTANCE gInstance;
HWND ghwnd;
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
	switch(msg){
	case WM_DESTROY:
		gameover = true;
		break;
	case WM_KEYDOWN:
		gameover = true;
		break;
	}
	return DefWindowProc(hwnd,msg,wParam,lParam);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE prevInstance,PSTR CmdLine,int iCmd){
	gInstance = hInstance;
	MSG msg;
	int full = MessageBox(NULL,"Fullscreen?",NULL,MB_YESNO);
	switch(full){
	case IDYES:
		fullscreen = true;
		break;
	case IDNO:
		fullscreen = false;
		break;
	}
	DWORD style;
	ULONG width, height;
	WNDCLASS wc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
	wc.lpfnWndProc = WndProc;
	wc.hInstance = gInstance;
	wc.lpszClassName = "Class";
	wc.lpszMenuName = NULL;
	wc.style = CS_OWNDC;
	RegisterClass(&wc);
	if(fullscreen){
		width = GetSystemMetrics(SM_CXSCREEN);
		height = GetSystemMetrics(SM_CYSCREEN);
		style = WS_POPUP;
	}
	else{
		width = gwidth;
		height = gheight;
		style = WS_OVERLAPPED|WS_SYSMENU;
	}
	ghwnd = CreateWindow("Class","Game",style,0,0,width,height,NULL,NULL,gInstance,NULL);
	ShowWindow(ghwnd,iCmd);
	UpdateWindow(ghwnd);
	InitMyD3D(ghwnd,fullscreen,gwidth,gheight);
	while(!gameover){
		if(PeekMessage(&msg,ghwnd,0,0,PM_REMOVE)){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	KillMyD3D();
	return 0;
}
I dont know why it doesn''t work could someone nudge me in the right direction. I have never split up files before. But i dont want to have to do the direct3d initialization every time i code something. Thanks, Cory
Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|

Share this post


Link to post
Share on other sites
thanks man i just remembered taht



Favorite Quotes:Gandalf: You shall not pass!|Smeagol: We don''t need you!|Sloth: Hey you guys!|

Share this post


Link to post
Share on other sites