因此,我的团队一直在尝试实现我们自己的 shared_ptr 实现,以便我们可以再次在调试模式(VS2013)下成功测试我们的游戏项目。但是,我们遇到了以下错误列表
10>GameLogic.lib(GameLevel.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class LevelRuleset>::operator bool(void)const " (??B?$Handle@VLevelRuleset@@@@QBE_NXZ) referenced in function "public: void __thiscall GameLevel::GameLevelUpdate(float)" (?GameLevelUpdate@GameLevel@@QAEXM@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class LevelRuleset>::operator bool(void)const " (??B?$Handle@VLevelRuleset@@@@QBE_NXZ)
10>GameLogic.lib(GameLogicBehaviors.obj) : error LNK2019: unresolved external symbol "class Handle<class Component> __cdecl static_handle_cast<class Component,class ScaleBehavior>(class Handle<class ScaleBehavior> const &)" (??$static_handle_cast@VComponent@@VScaleBehavior@@@@YA?AV?$Handle@VComponent@@@@ABV?$Handle@VScaleBehavior@@@@@Z) referenced in function "public: void __thiscall GameLogic::AddGrowShrinkPlayer(unsigned long)" (?AddGrowShrinkPlayer@GameLogic@@QAEXK@Z)
10>Graphics.lib(Graphics.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Camera>::operator bool(void)const " (??B?$Handle@VCamera@@@@QBE_NXZ) referenced in function "private: void __thiscall GraphicsSystem::LoadGeneratedObjects(void)" (?LoadGeneratedObjects@GraphicsSystem@@AAEXXZ)
10>Graphics.lib(AntTweakSys.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class Camera>::operator bool(void)const " (??B?$Handle@VCamera@@@@QBE_NXZ)
10>Graphics.lib(DX11.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class Camera>::operator bool(void)const " (??B?$Handle@VCamera@@@@QBE_NXZ)
10>Graphics.lib(Graphics.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Debug>::operator bool(void)const " (??B?$Handle@VDebug@@@@QBE_NXZ) referenced in function "private: void __thiscall GraphicsSystem::LoadGeneratedObjects(void)" (?LoadGeneratedObjects@GraphicsSystem@@AAEXXZ)
10>Graphics.lib(AntTweakSys.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class Debug>::operator bool(void)const " (??B?$Handle@VDebug@@@@QBE_NXZ)
10>Graphics.lib(GFXMessageHandler.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class Debug>::operator bool(void)const " (??B?$Handle@VDebug@@@@QBE_NXZ)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Group>::operator bool(void)const " (??B?$Handle@VGroup@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class RigidBody>::operator bool(void)const " (??B?$Handle@VRigidBody@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(DX11.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class RigidBody>::operator bool(void)const " (??B?$Handle@VRigidBody@@@@QBE_NXZ)
10>Physics.lib(Physics.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class RigidBody>::operator bool(void)const " (??B?$Handle@VRigidBody@@@@QBE_NXZ)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Collider>::operator bool(void)const " (??B?$Handle@VCollider@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(DX11.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class Collider>::operator bool(void)const " (??B?$Handle@VCollider@@@@QBE_NXZ)
10>Physics.lib(Physics.obj) : error LNK2001: unresolved external symbol "public: __thiscall Handle<class Collider>::operator bool(void)const " (??B?$Handle@VCollider@@@@QBE_NXZ)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Controller>::operator bool(void)const " (??B?$Handle@VController@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Spawner>::operator bool(void)const " (??B?$Handle@VSpawner@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class PlayerStats>::operator bool(void)const " (??B?$Handle@VPlayerStats@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Gun>::operator bool(void)const " (??B?$Handle@VGun@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Owner>::operator bool(void)const " (??B?$Handle@VOwner@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class StatModifier>::operator bool(void)const " (??B?$Handle@VStatModifier@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Graphics.lib(AntTweakSys.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class LifeTime>::operator bool(void)const " (??B?$Handle@VLifeTime@@@@QBE_NXZ) referenced in function "private: static void __stdcall AntTweakSystem::AddObjectBar(void *)" (?AddObjectBar@AntTweakSystem@@CGXPAX@Z)
10>Input.lib(Input.obj) : error LNK2019: unresolved external symbol _SDL_GetError referenced in function "public: virtual void __thiscall InputSystem::Initialize(void)" (?Initialize@InputSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2001: unresolved external symbol _SDL_GetError
10>Input.lib(Input.obj) : error LNK2019: unresolved external symbol _SDL_PollEvent referenced in function "private: void __thiscall InputSystem::HandleEvents(void)" (?HandleEvents@InputSystem@@AAEXXZ)
10>Input.lib(Input.obj) : error LNK2019: unresolved external symbol _SDL_EventState referenced in function "private: void __thiscall InputSystem::HandleEvents(void)" (?HandleEvents@InputSystem@@AAEXXZ)
10>Input.lib(Input.obj) : error LNK2019: unresolved external symbol _SDL_Init referenced in function "public: virtual void __thiscall InputSystem::Initialize(void)" (?Initialize@InputSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2001: unresolved external symbol _SDL_Init
10>Input.lib(Input.obj) : error LNK2019: unresolved external symbol _SDL_QuitSubSystem referenced in function "public: virtual int __thiscall InputSystem::Release(void)" (?Release@InputSystem@@UAEHXZ)
10>Windows.lib(Windows.obj) : error LNK2001: unresolved external symbol _SDL_QuitSubSystem
10>Input.lib(Input.obj) : error LNK2019: unresolved external symbol "public: __thiscall Handle<class Component>::operator bool(void)const " (??B?$Handle@VComponent@@@@QBE_NXZ) referenced in function "private: void __thiscall InputSystem::HandleMessage(void)" (?HandleMessage@InputSystem@@AAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_RWFromFile referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_MapRGB referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_FreeSurface referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_LoadBMP_RW referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_FillRect referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_CreateWindow referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_SetWindowIcon referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_GetWindowSize referenced in function "public: virtual void __thiscall WindowSystem::TransmitMessage(class std::shared_ptr<class Message>)" (?TransmitMessage@WindowSystem@@UAEXV?$shared_ptr@VMessage@@@std@@@Z)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_MinimizeWindow referenced in function "public: virtual void __thiscall WindowSystem::TransmitMessage(class std::shared_ptr<class Message>)" (?TransmitMessage@WindowSystem@@UAEXV?$shared_ptr@VMessage@@@std@@@Z)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_GetWindowSurface referenced in function "public: virtual void __thiscall WindowSystem::Initialize(void)" (?Initialize@WindowSystem@@UAEXXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_DestroyWindow referenced in function "public: virtual int __thiscall WindowSystem::Release(void)" (?Release@WindowSystem@@UAEHXZ)
10>Windows.lib(Windows.obj) : error LNK2019: unresolved external symbol _SDL_ShowSimpleMessageBox referenced in function "private: void __thiscall WindowSystem::ErrorPopUp(class std::shared_ptr<class ErrorMessage> const &)" (?ErrorPopUp@WindowSystem@@AAEXABV?$shared_ptr@VErrorMessage@@@std@@@Z)
10>A:\Mercurial\CodeFish\Build\AntTweakDebugWin32\Game.exe : fatal error LNK1120: 32 unresolved externals
我们目前担心的主要问题是 Handle 类中运算符 bool 的 LNK2019。作为参考,这里是整个类:
template <class TYPE>
class Handle;
template <class TYPE_TO_CAST_TO, class TYPE_TO_CAST_FROM>
Handle<TYPE_TO_CAST_TO> static_handle_cast(Handle<TYPE_TO_CAST_FROM> const& subject);
template <class TYPE>
class Handle : public HandleRegistrar
{
// friend all Handles so that we may convert them
template<class U> friend class Handle;
template<class T, class U> friend Handle<T> static_handle_cast(Handle<U> const& subject);
private:
bool m_weak;
int* m_ref_count;
TYPE** m_ptr;
public:
void destruct(void);
int use_count(void) const;
bool expired(void) const;
void swap(Handle<TYPE>& rhs);
TYPE* get(void);
TYPE* get(void) const;
template<typename TYPE2> Handle<TYPE>& operator=(const Handle<TYPE2>& rhs);
Handle<TYPE>& operator=(const Handle<TYPE>& rhs);
template<typename TYPE2> Handle<TYPE>& operator=(TYPE2* rhs);
TYPE* operator->(void);
TYPE* operator->(void) const;
TYPE& operator*(void);
TYPE& operator*(void) const;
bool operator==(const Handle<TYPE>& rhs);
void operator%(Handle<TYPE>& rhs);
operator bool(void) const;
public:
~Handle(void);
Handle(const Handle<TYPE>& rhs, bool weak = false);
template<typename TYPE2> Handle(const Handle<TYPE2>& rhs, bool weak = false);
Handle(TYPE& object_to_point_at, bool weak = false);
Handle(TYPE*&& pointer_to_object, bool weak = false);
Handle(void);
};
我们在 .cpp 文件中没有任何 Handle 类的实现,它完全在头文件中实现。一段时间以来,我一直在寻找解决这个问题的方法,并浏览了许多关于 SO 的 LNK2019 文章,希望能找到有关此问题的任何信息……感谢您提供任何帮助或洞察可能发生的事情。我们的游戏项目有很多东西在里面,所以如果需要更多信息,我会提供。
关于项目的事情: -
静态链接,代码分布在 11 个库中。
- 使用预编译的头文件。