开发者

error LNK2001: unresolved external symbol

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();开发者_JAVA百科
};

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜