Unresolved External Symbol- Error in guide?

2019-09-05 15:59发布

问题:

So I've been trying to fix a weird bug in a game engine SDK where the Windows loading cursor is used instead of the game's own cursor. The fix for this is here: http://www.crydev.net/wiki/index.php/Use_Custom_Cursor#Step_1:_Fixing_The_Cursor_Bug.

I have followed the fix, but I keep getting these when building the game DLL:

Error   1   error LNK2019: unresolved external symbol "public: __thiscall MODCursor::MODCursor(void)" (??0MODCursor@@QAE@XZ) referenced in function "public: __thiscall CGame::CGame(void)" (??0CGame@@QAE@XZ)  C:\Users\User\Desktop\Crytek\Mods\CryEngine2\Code\Game.obj  GameDll

Error   2   error LNK2019: unresolved external symbol "public: __thiscall MODCursor::~MODCursor(void)" (??1MODCursor@@QAE@XZ) referenced in function "public: virtual __thiscall CGame::~CGame(void)" (??1CGame@@UAE@XZ)    C:\Users\User\Desktop\Crytek\Mods\CryEngine2\Code\Game.obj  GameDll

Yeah, normally I can fix this issue quite easily by defining the class properly, but it hasn't worked in this case. What can I be doing wrong?

The files are as they are in the guide for the fix, so there isn't really any point in posting the files here since they would be a waste of space on here. If the files are really needed to investigate this issue, I'll upload them if anyone requests them.

Perhaps there's an error within the fix itself? One possible difference from the fix to my build is that the fix is using Visual Studio 2008, I am using Visual Studio 2013.

回答1:

Maybe try to put it all inside .h file:

#ifndef _MOD_CURSOR
#define _MOD_CURSOR

#include <windows.h>
#include "resource.h"

#undef GetUserName // This is a macro in windows.h, gives issues with GetUserName() of ISystem

class MODCursor : public ISystemEventListener
{
public:
    MODCursor() {
        gEnv->pSystem->GetISystemEventDispatcher()->RegisterListener(this);
        m_cursor = LoadCursor((HINSTANCE)g_hInst, MAKEINTRESOURCE(IDC_CURSOR1));
        SetCursor(m_cursor);
    }
    ~MODCursor(){
        gEnv->pSystem->GetISystemEventDispatcher()->RemoveListener(this);
    }
private:
    virtual void OnSystemEvent( ESystemEvent event,UINT_PTR wparam,UINT_PTR lparam ) {
        if(event == ESYSTEM_EVENT_TOGGLE_FULLSCREEN || event == ESYSTEM_EVENT_RESIZE || event == ESYSTEM_EVENT_CHANGE_FOCUS){
            if (m_cursor != GetCursor()) 
                SetCursor(m_cursor);
        }
    }
    HCURSOR m_cursor;
};
#endif


标签: c++ dll crysis