Page 1 of 1

linker error

Posted: Tue Jan 18, 2011 5:25 pm
by koso
Hi

i am trying to make my own small library, to put together graphics irrklsng and stuff. but when i am trying to compile i get this

Code: Select all

1>TGlobals.obj : error LNK2005: "void __cdecl rotateNode(class irr::scene::ISceneNode *,class irr::core::vector3d<float>)" (?rotateNode@@YAXPAVISceneNode@scene@irr@@V?$vector3d@M@core@3@@Z) already defined in techEngine.obj
1>TGlobals.obj : error LNK2005: "void __cdecl translateNode(class irr::scene::ISceneNode *,class irr::core::vector3d<float>)" (?translateNode@@YAXPAVISceneNode@scene@irr@@V?$vector3d@M@core@3@@Z) already defined in techEngine.obj
1>TRender.obj : error LNK2005: "void __cdecl rotateNode(class irr::scene::ISceneNode *,class irr::core::vector3d<float>)" (?rotateNode@@YAXPAVISceneNode@scene@irr@@V?$vector3d@M@core@3@@Z) already defined in techEngine.obj
1>TRender.obj : error LNK2005: "void __cdecl translateNode(class irr::scene::ISceneNode *,class irr::core::vector3d<float>)" (?translateNode@@YAXPAVISceneNode@scene@irr@@V?$vector3d@M@core@3@@Z) already defined in techEngine.obj
can someone explain me what is going on? i want to understand it for future.

thx

Posted: Tue Jan 18, 2011 6:20 pm
by Radikalizm
EDIT: Nevermind ^^

Posted: Tue Jan 18, 2011 6:52 pm
by Alpha Omega
It say already defined

(?translateNode@@YAXPAVISceneNode@scene@irr@@V?$vector3d@M@core@3@@Z) already defined in techEngine.obj
Are you perhaps trying to compile and using?

#include <file.cpp> because your not supposed to do that.

Posted: Thu Jan 20, 2011 12:31 am
by Iyad
Maybe its occuring due to circular dependency, be sure that your files does not include themselfs more than once, use include guards or rework on your code. Sometimes, if 2 classes or more are interdependant, you can try to use a forward declaration, then redefine your declaration in another file.

Posted: Thu Jan 20, 2011 12:41 am
by Radikalizm
Iyad wrote:Maybe its occuring due to circular dependency, be sure that your files does not include themselfs more than once, use include guards or rework on your code
This could very well be the problem
You should make it a standard practice to immediately add this to a newly created header file:

Code: Select all

#ifndef    __FILE_NAME_H__
#define    __FILE_NAME_H__

// You can name the define anything you want, as long as it remains unique throughout your program


/*
CODE GOES HERE
*/

#endif    // __FILE_NAME_H__


Posted: Thu Jan 20, 2011 1:06 am
by Anthony
second that of Radkalizm

But it only counts for header files.

To keep them unique, just use the filename of the header, i.e.:

Code: Select all

// header file: header.h
#ifndef _HEADER_H_
etc.
as filenames are unique too (unless you name them into different directories the same, wich you shouldn't ;) )