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

Posted on 2005-03-31
Medium Priority
Last Modified: 2008-02-07
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.
Question by:antaren
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 55

Accepted Solution

Jaime Olivares earned 1600 total points
ID: 13673940
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;
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13673957
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.

Author Comment

ID: 13674310
Thanks allot man.

Initialized it before any function calls, and it works like a charm now.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question