Jump to content
  • Advertisement
Sign in to follow this  

How to use a custom class without adding it to the project?

This topic is 3165 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'm working through a DirectX book and I want to use one of the author's supplied classes - GameTimer, for the timer in my code. Rather than find it and add it to my project every time, how could I say #include <GameTimer.h> and have the class just work? I tried adding the folder with the header and source files to the VC++ Directories in the settings page (I'm using VS2008), so the compiler won't complain about finding the file - that seems to work (Intellisense also works for the class, so it's seeing the the class), but whenever I try to compile, it gives me a linker error: main.obj : error LNK2019: unresolved external symbol "public: __thiscall GameTimer::GameTimer(void)" (??0GameTimer@@QAE@XZ) referenced in function "void __cdecl `dynamic initializer for 'timer''(void)" (??__Etimer@@YAXXZ) fatal error LNK1120: 1 unresolved externals Any tips here?

Share this post

Link to post
Share on other sites
That class would need to have a library, source file or something to link the code with. Just a header file;


#ifndef _MyClass_h_
#define _MyClass_h_

class MyClass
int m_iVar;

int DoSomething(int what);


Does nothing itself except define how the MyClass interface is. So there must be either a library; static (lib) or dynamic (dll) to link with your project, or some Source File that must be added to each project using the implementation.

So basically, by including the header your project knows what MyClass _can_ do, but it does not know how (or more appropriately where) it does it, so MyClass will not work. (Hence the linker errors).

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!