需要帮助解决C++引擎/框架构建中的链接器错误

Need help solving linker error in C++ engine/framework construction

本文关键字:构建 链接 错误 框架 帮助 解决 C++ 引擎      更新时间:2023-10-16

我来这里是万不得已,因为我需要尽快获得帮助,以完成明天到期的作业。

我正在C++中组装一个简单的引擎来处理节点、纹理/资产加载和状态系统。我想尝试继续编码与资产相关的东西,但为了做到这一点,我需要状态系统正常工作。

应用.h

#pragma once
#include "AppGSMEGameStateManager.h"
class EGameStateManager;
class EApplication 
{
public:
    static void Init();
    static void RunApp(); 
    EGameStateManager* GetGameStateManager();

protected: 
    static int windowWidth;
    static int windowHeight;
    static bool fullScreen;
    static bool frameSync;
    static char* windowTitle;
};

目前,每当我尝试使用上面看到的指针时,在我的测试状态类和主.cpp中,我都会收到链接器错误。(见下文)

测试状态

.cpp
#include "AppGSMETestState.h"
#include "AppGSMEApplication.h"
#include <iostream>
ETestState::ETestState(EApplication* pApp){}
ETestState::~ETestState(){}
void ETestState::Update(float deltaTime)
{
    //if(INPUT::GetKey(KEY_T))
    //{
    //  cout << "Entered Test State" << endl;
    //}
    m_testTimer += deltaTime;
    if(m_testTimer > 3.0f)
    {
        m_pApp->GetGameStateManager()->ChangeState("Second TEST");
    }
}
void ETestState::Draw(){}

主要

.cpp
#include "GLglew.h"
#include "GLglfw.h"
#include <conio.h>
#include "AppGSMEApplication.h"
#include "AppGSMETestState.h"
void main()
{
    EApplication::Init();
    EApplication* pApp = new EApplication();
    pApp->GetGameStateManager()->SetState("TEST", new ETestState(pApp));
    EApplication::RunApp();
}

这是保存 TestState 中使用的应用程序指针的基本游戏状态类:

BASEGAMESTATE.h

#pragma once 
class EApplication;
class EGameStateManager;
class EBaseGameState
{
public:
    EBaseGameState(){}
    EBaseGameState(EApplication* pApp);
    //always make the destructor virtual !!
    virtual ~EBaseGameState();
    //all game states must define update and draw
    virtual void Update(float deltaTime)    = 0;
    virtual void Draw()                     = 0;

protected:
    EApplication* m_pApp;

};

这些是链接器错误:

Error   9   error LNK2019: unresolved external symbol "public: class EGameStateManager * __thiscall EApplication::GetGameStateManager(void)" (?GetGameStateManager@EApplication@@QAEPAVEGameStateManager@@XZ) referenced in function _main  D:Enginemain.obj
Error   10  error LNK2001: unresolved external symbol "public: class EGameStateManager * __thiscall EApplication::GetGameStateManager(void)" (?GetGameStateManager@EApplication@@QAEPAVEGameStateManager@@XZ)   D:EngineETestState.obj

通常我会把链接器错误归结为循环包含,但我已经写下了各种各样的序列图,没有任何东西包含包含它本身的东西。这可能是显而易见的。我真的很有压力。任何帮助将不胜感激。

链接器找不到该函数。你需要实现 GetGameStateManager() 函数