• Advertisement

Archived

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

Link error driveing me crazy!

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

I´m includeing ParticleSystem.cpp in the main file and if I create an object of the ParticleSystem-class then I get the link errors below, why? I havnen´t included it twice, declared/defined the functions twice either.
  
Linking...
projectx.obj : error LNK2005: "unsigned long * g_clrColorFade" (?g_clrColorFade@@3PAKA) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "struct D3DXCOLOR * g_clrColor" (?g_clrColor@@3PAUD3DXCOLOR@@A) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "public: __thiscall ParticleSystem::ParticleSystem(unsigned long,unsigned long,float)" (??0ParticleSystem@@QAE@KKM@Z) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "public: __thiscall ParticleSystem::~ParticleSystem(void)" (??1ParticleSystem@@QAE@XZ) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "public: long __thiscall ParticleSystem::InvalidateDeviceObjects(void)" (?InvalidateDeviceObjects@ParticleSystem@@QAEJXZ) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "public: long __thiscall ParticleSystem::Render(struct IDirect3DDevice8 *)" (?Render@ParticleSystem@@QAEJPAUIDirect3DDevice8@@@Z) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "public: long __thiscall ParticleSystem::RestoreDeviceObjects(struct IDirect3DDevice8 *)" (?RestoreDeviceObjects@ParticleSystem@@QAEJPAUIDirect3DDevice8@@@Z) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "public: long __thiscall ParticleSystem::Update(float,unsigned long,struct D3DXCOLOR const &,struct D3DXCOLOR const &,float,struct D3DXVECTOR3)" (?Update@ParticleSystem@@QAEJMKABUD3DXCOLOR@@0MUD3DXVECTOR3@@@Z) already d
efined in ParticleSystem.obj
Debug/projectx.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

projectx.exe - 9 error(s), 0 warning(s)
  

Share this post


Link to post
Share on other sites
Advertisement
Don''t include a .cpp, because you''ll make the code get generated twice. It will get compiled once as the .cpp, and once as the file that includes it.

Move the implementation to a .cpp file, leave the declaration in a .h file, and include only the .h file.

Share this post


Link to post
Share on other sites
Now, I´m includeing the ParticleSystem.h and not the .cpp-file, but I still get this link error. Why?!

  
--------------------Configuration: Project X - Win32 Debug--------------------
Linking...
projectx.obj : error LNK2005: "unsigned long * g_clrColorFade" (?g_clrColorFade@@3PAKA) already defined in ParticleSystem.obj
projectx.obj : error LNK2005: "struct D3DXCOLOR * g_clrColor" (?g_clrColor@@3PAUD3DXCOLOR@@A) already defined in ParticleSystem.obj
Debug/projectx.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

projectx.exe - 3 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Make the variables static and they will only be created once...

Share this post


Link to post
Share on other sites

  • Advertisement