linker error i dont quite understand

Started by
6 comments, last by AndyUni 17 years, 1 month ago
GameMaterial.obj : error LNK2001: unresolved external symbol "public: __thiscall Material::Material(void)" (??0Material@@QAE@XZ) is what i keep getting whilst trying to build the solution, yet when i compile each file in the poject they compile fine. its jsut this when i try and build the solution. any idea why i get this?
Advertisement
It looks like you have the declaration for a constructor for the Material class, but no definition. ie:
class Material{public:   Material( );   // declaration!...};// You need thisMaterial::Material( )   // definition!{}


HTH
thats the thing i do have a definition and a decleration
Definition:
class Material : public Resource< Material >
{
}

Decleration:
Material::Material( char *name, char *path ) : Resource< Material >( name, path )
{
}

im not sure if its to do with this though. its the class derived from material:

class GameMaterial : public Material
{
};

Decleration:
GameMaterial::GameMaterial( char *name, char *path ) : Material( name, path )
{
};


is it because i dont have brackets before GameMaterial? not at the pc with the code all on at the moment so cant check.
The linker is looking for the default Material constructor (e.g. one with no arguments). So, apparently you have a reference somewhere in your code to a Material (or Material derivative) that needs the default constructor, perhaps in a copy operation or similar.
but wouldnt that come up when trying to link indiviual files not the whole project?

also how would i fix something like this?

(getting prepared here for tomorrow when i go back into uni and get back on the code)
Having re-read your code it's not either of the first two things I thought it might be.

Something, somewhere, in your code is trying to create a material object using a default constructor that is declared but not defined. That's a certainty as far as I can see. From the snippets you've posted, it's not clear where - so we're going to need to see more code. (If you're away from the PC with all the code on, how have you been able to post the code you have posted, and know you've got it right? If your GameMaterial class did not construct the Material parent class in it's constructor, that'd cause this problem, so are you certain it does, and you've not just posted it here correctly but it's incorrect in the code?)
Quote:Original post by AndyUni
but wouldnt that come up when trying to link indiviual files not the whole project?


No, because this is a link-time error, not a compile-time error and individual files don't link, they just produce .obj files. When compiling individual source files, the compiler has no knowledge of (nor does it care) whether you have an actual implementation of a method anywhere. It's the linker that has the job of resolving all of that. So you won't see this problem until you try to link (e.g. when you build the whole project).
Quote:Original post by SunTzu
Having re-read your code it's not either of the first two things I thought it might be.

Something, somewhere, in your code is trying to create a material object using a default constructor that is declared but not defined. That's a certainty as far as I can see. From the snippets you've posted, it's not clear where - so we're going to need to see more code. (If you're away from the PC with all the code on, how have you been able to post the code you have posted, and know you've got it right? If your GameMaterial class did not construct the Material parent class in it's constructor, that'd cause this problem, so are you certain it does, and you've not just posted it here correctly but it's incorrect in the code?)


i came into uni early to try and fix this, the snippets were from printouts i did in note pad whilst doing the skeleton of the game.

but thanks for your help lads ive fixed it now it was because i had the an extra constructor in their that was a instance of Material() and removing that made the thing work. cheers for the advice

This topic is closed to new replies.

Advertisement