Ошибка компоновщика: LNK2019 генерируется в статически связанном проекте
Итак, моя команда пыталась реализовать собственную реализацию 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
Основная проблема, с которой мы сейчас беспокоимся, это LNK2019 для оператора bool в классе Handle. Для справки, вот класс в полном объеме:
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, он полностью реализован в заголовке. Я некоторое время искал решение этой проблемы и просмотрел так много статей LNK2019 о SO, надеясь найти что-нибудь об этой проблеме... Любая помощь или понимание того, что может произойти, ценится. В нашем игровом проекте много чего происходит, поэтому, если потребуется дополнительная информация, я ее предоставлю.
Вещи о проекте:
-Статически связанный код распространяется по 11 библиотекам.
-Предкомпилированные заголовки используются.