views:

48

answers:

2

I am receiving this error

>GXRenderManager.obj : error LNK2001: unresolved external symbol "private: static class GXRenderer * GXRenderManager::renderDevice" (?renderDevice@GXRenderManager@@0PAVGXRenderer@@A)

The following is my code...

GXDX.h

class GXDX: public GXRenderer {
public:
    void Render();
    void StartUp();
};

GXGL.h

class GXGL: public GXRenderer {
public:
    void Render();
    void StartUp();
};

GXRenderer

class GXRenderer {
public:
    virtual void Render() = 0;
    virtual void StartUp() = 0;

};

GXRenderManager.h

#ifndef GXRM
#define GXRM
#include <windows.h>
#include "GXRenderer.h"
#include "GXDX.h"
#include "GXGL.h"

enum GXDEVICE {
    DIRECTX,
    OPENGL
};

class GXRenderManager {
public:
    static int Ignite(GXDEVICE);

private:
    static GXRenderer *renderDevice;

};

#endif

GXRenderManager.cpp

#include "GXRenderManager.h"

    int GXRenderManager::Ignite(GXDEVICE DeviceType)
    {
        switch(DeviceType)
        {
        case DIRECTX:
            GXRenderManager::renderDevice = new GXDX;
            return 1;
            break;
        case OPENGL:
            GXRenderManager::renderDevice = new GXGL;
            return 1;
            break;
        default:
            return 0;
        }
    }

main.cpp

#include "GXRenderManager.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    return 0;
}

I am not trying to get it to do anything. I am just trying to compile with no errors. I am new with all this so if anyone can give me a hand. that will be great. thanks

A: 

Hi try this,

In Visual Studio C++, go to Tools->Options->Projects->VC++ Directories and choose "Show directories for:" in the upper right hand corner and select "Include files" -- and then enter the folder where the header files you'd be using are found.

Also go to Project->Properties->Linker->Input->Additional Dependencies and enter the full path of the library file you are using

for more info: http://www.codeguru.com/forum/showthread.php?t=289136

VoodooChild
thanks for the reply. all my header files are in the same place as the main.cpp and the vproj file (as far as the physical drive is concerned). I never previously had to add the path of my header files that were located in the same folder as my project files and source files. I don't see why that would make much difference now. All of these files are files I created within the project scope (within the solution explorer)
numerical25
The problem is that your linker cannot find the defintions of thosefunctions. Most likely you have forgotten to add the module where those function are defined to the project.
VoodooChild
Also note that: It's the header that contains the definitions of the classes. The actual implementation is most likely in a ".lib" file. You need to read the documentation for your library and pay attention to what you need to do with the .lib file, along with adding the header to your source.
VoodooChild
+2  A: 

You need an actual definition (or instance) for the static member GXRenderer::renderDevice. The class declares it, but there needs to be a definition of it in exactly one place.

In your GXRenderManager.cpp file have a line like so:

GXRenderer * GXRenderer::renderDevice = NULL;

or whatever initialization might be appropriate.

Michael Burr
+1 my answer exactly
Iulian Şerbănoiu
You know, I actually did that before, except I did not add the astricks. So I guess I was setting the location to null. Thanks
numerical25