Page 1 of 1

undefined reference to blah blah blah....

Posted: Fri Dec 29, 2006 2:03 am
by benny53
Ok,I'm making a simple game engine,and now,my compiler is going crazy on me. Its saying I have undefined references to my parent classes. Here is the code for two classes,one in which is getting a linker error:

ILoadedMesh(linker error/parent)

Code: Select all

#ifndef _ILOADEDMESH_H_
#define _ILOADEDMESH_H_

#include "includes.hpp"
#include "IBaseMesh.hpp"
#include "IManager.hpp"

class DLL_EXPORT ILoadedMesh : public IBaseMesh
{
public:
   ILoadedMesh(IManager* mgr,const c8* file);
   ~ILoadedMesh();
};

#endif // _ILOADEDMESH_H_
CLoadedMesh(child class)

Code: Select all

#ifndef _CLOADEDMESH_H_
#define _CLOADEDMESH_H_

#include "includes.hpp"
#include "IManager.hpp"
#include "ILoadedMesh.hpp"

class DLL_EXPORT CLoadedMesh : public ILoadedMesh
{
public:
   CLoadedMesh(IManager* mgr,const c8* file);
   ~CLoadedMesh();
};

#endif // _CLOADEDMESH_H_
So what causes these errors? Help would be greatly appreciated.

Posted: Fri Dec 29, 2006 11:24 am
by Xharock
Hmm not sure whether this would cause linker errors but in your child class you only need to include "ILoadedMesh.hpp" as in that file it also includes the other two. So essentially you're including the same files twice. Could you post the errors you are receiving? That might help.

Posted: Fri Dec 29, 2006 11:55 am
by Saturn
What does DLL_EXPORT evaluate to?
Are the functions declared in ILoadedMesh and IBaseMesh all implemented?
What are the exactly are the error messages?

Posted: Fri Dec 29, 2006 4:05 pm
by benny53
#define DLL_EXPORT __declspec (dllexport)

IBase has all of its functions declared with the code in its own class. The linker errors say there is an undefined reference to the constructors and deconstructors of ILoadedMesh in CLoadedMesh.o

Posted: Fri Dec 29, 2006 4:25 pm
by Saturn
benny53 wrote:The linker errors say there is an undefined reference to the constructors and deconstructors of ILoadedMesh in CLoadedMesh.o
So did you define these? I only see the declarations. Try adding {} like this, if you don't define them elsewhere already.

Code: Select all

class DLL_EXPORT ILoadedMesh : public IBaseMesh
{
public:
   ILoadedMesh(IManager* mgr,const c8* file) {}
   virtual ~ILoadedMesh() {}
};
Also, be sure to make the IBaseMesh destructor virtual, if not done so already. This has nothing to do with this, but if you don't do this, you get unexpected behaviour when you delete an instance using a IBaseMesh or ILoadedMesh pointer.