升级到 Visual Studio 2019 后无法解析的外部符号 ATL::IAtlMemMgr
Unresolved external symbol ATL::IAtlMemMgr after upgrading to Visual Studio 2019
我目前正在将我们的源代码从 VS2012 升级到 VS2019。一个使用 MFC 的项目没有 link 成功:
fatal error LNK1120: 4 unresolved externals
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Allocate(unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Allocate(int,int)"
error LNK2001: unresolved external symbol "public: void __cdecl ATL::IAtlMemMgr::Free(void *)" referenced in function "public: virtual void __cdecl ATL::CAtlStringMgr::Free(struct ATL::CStringData *)"
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Reallocate(void *,unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
error LNK2001: unresolved external symbol "public: virtual struct ATL::CStringData * __cdecl ATL::IAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
我们正在使用多字节字符集 (MBCS) 进行构建。我的第一个想法是,我们缺少 mbcs 库。但如前所述 here,这些库是默认安装的 "when you select MFC and ATL support"。
我在代码中添加了atlbase.h,并手动添加了atls.lib作为附加依赖,但并没有解决问题。
如何找出缺少哪个库?
编辑 1:
让我们来看看atlmem.h:
__interface __declspec(uuid("654F7EF5-CFDF-4df9-A450-6C6A13C622C0")) IAtlMemMgr{
public:
_Ret_maybenull_ _Post_writable_byte_size_(nBytes) void* Allocate(_In_ size_t nBytes) throw();
据我所知,这是未找到的符号之一。如能红一下__interface keyword, it implicitly makes the functions pure virtual. These kind of linker errors might be caused by non pure virtual function declarations.
可能存在使 __interface 中的函数不是纯虚拟函数的错误?
在排除几乎所有源文件并注释掉大量功能后,我可以看到链接器错误与 <afxwin.h>
相关。将 <afxwin.h>
移动到每个源文件的顶部消除了链接器错误。
但是,我很想知道为什么使用 VS2012 进行编译会产生与 VS2019 相比的另一种行为。
我目前正在将我们的源代码从 VS2012 升级到 VS2019。一个使用 MFC 的项目没有 link 成功:
fatal error LNK1120: 4 unresolved externals
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Allocate(unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Allocate(int,int)"
error LNK2001: unresolved external symbol "public: void __cdecl ATL::IAtlMemMgr::Free(void *)" referenced in function "public: virtual void __cdecl ATL::CAtlStringMgr::Free(struct ATL::CStringData *)"
error LNK2001: unresolved external symbol "public: void * __cdecl ATL::IAtlMemMgr::Reallocate(void *,unsigned __int64)" referenced in function "public: virtual struct ATL::CStringData * __cdecl ATL::CAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
error LNK2001: unresolved external symbol "public: virtual struct ATL::CStringData * __cdecl ATL::IAtlStringMgr::Reallocate(struct ATL::CStringData *,int,int)"
我们正在使用多字节字符集 (MBCS) 进行构建。我的第一个想法是,我们缺少 mbcs 库。但如前所述 here,这些库是默认安装的 "when you select MFC and ATL support"。
我在代码中添加了atlbase.h,并手动添加了atls.lib作为附加依赖,但并没有解决问题。
如何找出缺少哪个库?
编辑 1: 让我们来看看atlmem.h:
__interface __declspec(uuid("654F7EF5-CFDF-4df9-A450-6C6A13C622C0")) IAtlMemMgr{
public:
_Ret_maybenull_ _Post_writable_byte_size_(nBytes) void* Allocate(_In_ size_t nBytes) throw();
据我所知,这是未找到的符号之一。如能红一下__interface keyword, it implicitly makes the functions pure virtual. These kind of linker errors might be caused by non pure virtual function declarations.
可能存在使 __interface 中的函数不是纯虚拟函数的错误?
在排除几乎所有源文件并注释掉大量功能后,我可以看到链接器错误与 <afxwin.h>
相关。将 <afxwin.h>
移动到每个源文件的顶部消除了链接器错误。
但是,我很想知道为什么使用 VS2012 进行编译会产生与 VS2019 相比的另一种行为。