Question regarding LNK2005

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
kaltz
Posts: 9
Joined: July 17th, 2012, 5:03 am

Question regarding LNK2005

Post by kaltz » July 17th, 2012, 11:53 am

So I have this main.cpp and another header and cpp file called system.h and system.cpp

I declared the LPDIRECT3D9 and LPDIRECT3DDEVICE9 type variables like:

extern LPDIRECT3D9 g_pD3D;
extern LPDIRECT3DDEVICE9 g_pd3dDevice;

on my system.h and initialized them inside my system.cpp file

at my main.cpp, I included the system.h file like :

#include "system.h"

when I tried to compile it, it said that something along the lines of:

error LNK2005: "struct IDirect3D9 * g_pD3D" (?g_pD3D@@3PAUIDirect3D9@@A) already defined in main.obj

and the same error for the second variable.

I haven't defined or declared the two variables on the main.cpp, I haven't even called the two variables at all.

I temporarily solved the problem by using extern on the two variables on system.h
But I have a feeling that this might not be a 100% solution.

I was wondering what was causing the problem and how can I fix it..

Thank you in advance.

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: Question regarding LNK2005

Post by LuX » July 17th, 2012, 8:38 pm

Dunno. Maybe the header is viewed multiple times. Do you have a header guard in it?
A header guard will make sure the file is only read once.
ʕ •ᴥ•ʔ

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Question regarding LNK2005

Post by chili » July 18th, 2012, 3:42 am

Can't say without seeing your code. It's some sort of redefinition.
Chili

Post Reply