• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Linker Problem, Please Help: Skeleton.obj : error LNK2001: unresolved external symbol "protected: static class GameEngine * GameEngine::m_pGameEngine" (?m_pGameEngine@GameEngine@@1PAV1@A)

I am creating a simple game engine, to get my feet wet.

The program I've created compiles, but it does not link correctly.  It gives the following error:

Skeleton.obj : error LNK2001: unresolved external symbol "protected: static class GameEngine * GameEngine::m_pGameEngine" (?m_pGameEngine@GameEngine@@1PAV1@A)

I've google'ed for a solution, but all the results come back about missing library dependancies or directions on including header files into the project, neither of which I believe to be the problem.

I'm pritty sure its a problem with how I'm using the GameEngine class in my program.  Here is the main referance for the member variable m_pGameEngine:

In class GameEngine

     // GetEngine method allows outside access to the GameEngine pointer
     static GameEngine*  GetEngine() { return m_pGameEngine; };

In GameEngine::GameEngine()

      // Set the member variables for the game engine
      m_pGameEngine = this;

Thanks for the help.
  • 2
1 Solution
Jaime OlivaresSoftware ArchitectCommented:
in your gameengine.cpp (or whatever is it name), you have to initialize the static variable OUTSIDE any class function:

GameEngine *GameEngine::m_pGameEngine = NULL;
Jaime OlivaresSoftware ArchitectCommented:
To explain more, every static data member must be initialized to some value, normally this initialization is made in the .cpp file of the class implementation (not in .h file because it can't initialized many times).
In this case, the pointer will be initialized to NULL, then, in the constructor will be re-initialized to the proper value.
antarenAuthor Commented:
Thanks allot man.

Initialized it before any function calls, and it works like a charm now.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now