"Unresolved external" linker error

Started by
9 comments, last by Leviathan569 22 years ago
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?
------------------------leviathan569@hotmail.com------------------------
Advertisement
Not without telling us what the linker actually said. "Unresolved external" is akin to "something''s wrong".
The error said "[Linker error] Unresolved external ''TAnimation::TAnimation(TGameApp*, TDirectDraw*, const char*, int, int, int, int, int)'' referenced from C:\blablabla\Main.obj"
------------------------leviathan569@hotmail.com------------------------
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.
Linker error = missing library or object file.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
It''s not just the constructor. Every function in the class, even the ones I don''t use in my program, give this error.
------------------------leviathan569@hotmail.com------------------------
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.
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.
------------------------leviathan569@hotmail.com------------------------
Don''t use symbols or identifiers with leading underscores; the standard specifies that they''re reserved for the implementation.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ ]
[ MS RTFM [MSDN] | SGI STL Docs | Boost ]
[ Google! | Asking Smart Questions | Jargon File ]
Thanks to Kylotan for the idea!
#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.

This topic is closed to new replies.

Advertisement