ATL Based Linker Errors

2019-05-01 04:03发布

问题:

I got a linking problem with atls.lib lately. I updated my linker's additional dependencies lines with:

comctl32.lib
C:\WinDDK\7600.16385.1\lib\ATL\i386\atls.lib
C:\WinDDK\7600.16385.1\lib\ATL\i386\atl.lib
C:\WinDDK\7600.16385.1\lib\ATL\i386\atlsd.lib

However, now, I started getting these errors.

What can cause these problems?

Thank you very much.

------ Build started: Project: hede, Configuration: Debug Win32 ------
Linking...
atlsd.lib(externs.obj) : error LNK2005: "char const * const g_pszUpdateEventName" (?g_pszUpdateEventName@@3PBDB) already defined in atls.lib(externs.obj)
atlsd.lib(externs.obj) : error LNK2005: "char const * const g_pszAllocFileMapName" (?g_pszAllocFileMapName@@3PBDB) already defined in atls.lib(externs.obj)
atlsd.lib(externs.obj) : error LNK2005: "char const * const g_pszKernelObjFmt" (?g_pszKernelObjFmt@@3PBDB) already defined in atls.lib(externs.obj)
atlsd.lib(externs.obj) : error LNK2005: "class CAtlAllocator g_Allocator" (?g_Allocator@@3VCAtlAllocator@@A) already defined in atls.lib(externs.obj)
SettingPropPage.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
stdafx.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
trace.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
util.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
genericpropclasses.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
hede.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
hede2.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
propclasses.obj : error LNK2001: unresolved external symbol __forceAtlDllManifest
propclasses.obj : error LNK2019: unresolved external symbol __imp__AtlWinModuleAddCreateWndData@12 referenced in function "public: void __thiscall ATL::CAtlWinModule::AddCreateWndData(struct ATL::_AtlCreateWndData *,void *)" (?AddCreateWndData@CAtlWinModule@ATL@@QAEXPAU_AtlCreateWndData@2@PAX@Z)
propclasses.obj : error LNK2019: unresolved external symbol "void __stdcall ATL::__FreeStdCallThunk(void *)" (?__FreeStdCallThunk@ATL@@YGXPAX@Z) referenced in function "public: static void __cdecl ATL::_stdcallthunk::operator delete(void *)" (??3_stdcallthunk@ATL@@SAXPAX@Z)
propclasses.obj : error LNK2019: unresolved external symbol __imp__AtlWinModuleExtractCreateWndData@4 referenced in function "public: void * __thiscall ATL::CAtlWinModule::ExtractCreateWndData(void)" (?ExtractCreateWndData@CAtlWinModule@ATL@@QAEPAXXZ)
propclasses.obj : error LNK2019: unresolved external symbol "void * __stdcall ATL::__AllocStdCallThunk(void)" (?__AllocStdCallThunk@ATL@@YGPAXXZ) referenced in function "public: static void * __cdecl ATL::_stdcallthunk::operator new(unsigned int)" (??2_stdcallthunk@ATL@@SAPAXI@Z)
stdafx.obj : error LNK2019: unresolved external symbol __imp__AtlUpdateRegistryFromResourceD@20 referenced in function "public: long __stdcall ATL::CAtlModule::UpdateRegistryFromResourceDHelper(wchar_t const *,int,struct ATL::_ATL_REGMAP_ENTRY *)" (?UpdateRegistryFromResourceDHelper@CAtlModule@ATL@@QAGJPB_WHPAU_ATL_REGMAP_ENTRY@2@@Z)
stdafx.obj : error LNK2019: unresolved external symbol __imp__AtlCreateRegistrar@4 referenced in function "public: long __stdcall ATL::CAtlModule::UpdateRegistryFromResourceDHelper(wchar_t const *,int,struct ATL::_ATL_REGMAP_ENTRY *)" (?UpdateRegistryFromResourceDHelper@CAtlModule@ATL@@QAGJPB_WHPAU_ATL_REGMAP_ENTRY@2@@Z)
stdafx.obj : error LNK2019: unresolved external symbol __imp__AtlCallTermFunc@4 referenced in function "public: void __thiscall ATL::CAtlModule::Term(void)" (?Term@CAtlModule@ATL@@QAEXXZ)
Debug/hede.exe : fatal error LNK1120: 8 unresolved externals
Build log was saved at "file://c:\Users\JohnDoe\Desktop\myproject\hede\Debug\BuildLog.htm"
hede- 20 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

回答1:

In project settings change "Use of ATL" from "Dynamic Link to ATL" to "Static Link to ATL".



回答2:

I had to debug this issue as well. Seems the DLL bulid is not working since a number of functions are missing in atl.lib. I switched "Use of ATL" to "Static link to ATL". After that I had only 3 missing symbols left and I found that these are defined within atlthunk.lib. This one is never referenced in atlbase.h. That's why I added

#pragma comment(lib, "atlthunk.lib")

to atlbase.h right before the debug yes/no section for atls.lib/atlsd.lib

After that the build was successfull.



回答3:

atls.lib is ATL's static library. atlsd.lib is that library's debug version. You're linking to both on the same build, so you get multiple definitions. In addition, atl.lib is what you should link to if you want to use ATL's dynamic library. So, either use atl.lib, or use atls.lib in your release build and atlsd.lib in your debug build. But don't mix them together.