• Advertisement

Archived

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

"Unresolved external" linker error

This topic is 5842 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 get this error when I want to use a class from an external cpp file. The class declaration is in a .h file and the functions are in a .cpp file. When I want to use any of the methods from the class, I get the linker error. My code looks like this: TAnimation* Animation ... Animation = new TAnimation(...); Animation->NextFrame(); With other files and classes I never had any problems. I included all header files and libraries and now I have no idea what might be causing this problem. Does anybody know what I am doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Not without telling us what the linker actually said. "Unresolved external" is akin to "something''s wrong".

Share this post


Link to post
Share on other sites
The error said "[Linker error] Unresolved external ''TAnimation::TAnimation(TGameApp*, TDirectDraw*, const char*, int, int, int, int, int)'' referenced from C:\blablabla\Main.obj"

Share this post


Link to post
Share on other sites
When you''re linking, are you sure you''re also linking in the other object file?

It''s also possible that you''ve declared that form of the constructor in the .h file, but never in the .cpp. Check your argument list VERY carefully in all three places, including where you have done default arguments. Also remember that const is different from non-const, and references are different from non-references.

Share this post


Link to post
Share on other sites
Linker error = missing library or object file.

Share this post


Link to post
Share on other sites
It''s not just the constructor. Every function in the class, even the ones I don''t use in my program, give this error.

Share this post


Link to post
Share on other sites
Could you post the class declaration from the header and the funcion defs from the .cpp so we could see them? Maybe then we could help you better.

Share this post


Link to post
Share on other sites
Okay, I''ve found the problem. To avoid multiple declaration, I put this in the header file:

#ifndef _Animation
#define _Animation

class definition

#endif

Now I accidentially put this in both the header and the source file so it got all fucked up.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
#ifndef CLASS_NAME_H
#define CLASS_NAME_H

// ...

#endif // CLASS_NAME_H

The above is what I do, and from what I understand is rather common.

Share this post


Link to post
Share on other sites

  • Advertisement