gpt4 book ai didi

c++ - 错误 LNK2019 : unresolved external symbol error

转载 作者:太空宇宙 更新时间:2023-11-04 11:36:46 25 4
gpt4 key购买 nike

我收到这些错误消息

2>main.obj : error LNK2019: unresolved external symbol "public: __thiscall CEngine::CEngine(void)" (??0CEngine@@QAE@XZ) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::SetWindowSize(int,int,char const *,int)" (?SetWindowSize@CEngine@@QAEXHHPBDH@Z) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall CEngine::Begin(void)" (?Begin@CEngine@@QAEXXZ) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayWidth(void)" (?GetDisplayWidth@CEngine@@QAEHXZ) referenced in function _WinMain@16

2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall CEngine::GetDisplayHeight(void)" (?GetDisplayHeight@CEngine@@QAEHXZ) referenced in function _WinMain@16

2>C:\Users\ethan\Desktop\C++ Projects\delveenginetest\Debug\delveenginetest.exe : fatal error LNK1120: 5 unresolved externals

这是我的解决方案:

Solution 'delveenginetest' (2 projects)

DelveEngine

Include

delve.h

Engine.h

SetupSDL.h

stdafx.h

引擎.cpp

main.cpp

设置SDL.cpp

这是Engine.h

的代码
#pragma once
#include "SetupSDL.h"

class CEngine
{
public:
CEngine(void);
~CEngine(void);

void SetWindowSize(int winW, int winH, const char* GameName, int windowMode);
void Begin(void);

int GetDisplayWidth(void);
int GetDisplayHeight(void);
private:
int deskW;
int deskH;

bool playing;
CSetupSDL* sdl_setup;
};

Engine.cpp的代码

#include "Include/stdafx.h"
#include "Include/Engine.h"

CEngine::CEngine(void)
{
playing = true;

deskW = GetSystemMetrics(SM_CXSCREEN);
deskH = GetSystemMetrics(SM_CYSCREEN);
}


CEngine::~CEngine(void)
{
}

void CEngine::SetWindowSize(int winW, int winH, const char* GameName, int windowMode)
{
// set up SDL for use
sdl_setup = new CSetupSDL(winW, winH, GameName, windowMode);
}

void CEngine::Begin(void)
{
while (playing && sdl_setup->GetMainEvent()->type != SDL_QUIT)
{
sdl_setup->Begin();
sdl_setup->End();
}

playing = false;
}

int CEngine::GetDisplayWidth(void){ return deskW; }
int CEngine::GetDisplayHeight(void){ return deskH; }

DelveEngine 项目构建成功,而 delveenginetest 项目失败。

怎么了?我找遍了一个原因,找不到适合我的。

最佳答案

尽管您没有提供所有足够的信息来正确诊断您的问题,但我会尝试分享我认为可能是链接器错误的原因:

  1. 我想您提到的项目 delveenginetest 是为了为 DelveEngine 项目中的类设置单元测试。
  2. 由于您的 DelveEngine 项目中有一个 Main.cpp,我猜它只是作为可执行文件构建(成功)。
  3. 您的 delveenginetest 需要链接到 DelveEngine 项目提供的类,但这实际上是不可能的,因为 .exe 来自 DelveEngine 不能用于链接,您需要一个库将其导入另一个可执行文件(单元测​​试框架)。

我建议将你的类/源文件从 DelveEngine 项目中分离出来,组成一个静态或共享库,它可以从一个应用程序和测试框架中同时链接到一个单一的VS解决方案:

Solution 'DelveEngine' (3 projects)  
DelveEngineLib (project [.lib/.dll])
Include
delve.h
Engine.h
SetupSDL.h
Engine.cpp
SetupSDL.cpp
DelveEngine (project [.exe])
Main.cpp
delveenginetest (project [.exe])
Main.cpp (TestFramework main definition)

因为我不是很精通它,所以我实际上不知道 VS 2013 是否支持设置消耗虚拟 资源的项目(想想实际构建环境中的源链接),但是这可能是无需额外库即可设置应用程序和单元测试的替代方法。

关于c++ - 错误 LNK2019 : unresolved external symbol error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22793432/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com