ATL Based Linker Errors
Asked Answered
S

3

7

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 ==========
Spieler answered 20/6, 2012 at 15:57 Comment(3)
How did you solve the problem ?Rexanna
@Rexanna change your project properties. choose "Use ATL" in project properties. don't need to include anything. and, don't use express editions. good luck.Spieler
Where in project properties? o.OTwelve
G
4

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

Gyn answered 27/7, 2012 at 12:26 Comment(1)
That option seems to be gone in later versions of Visual Studio? (VS 2019 Community here)Chayachayote
F
4

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.

Fullrigged answered 21/8, 2015 at 15:50 Comment(0)
A
2

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.

Amaurosis answered 20/6, 2012 at 19:8 Comment(2)
But my console output told me to link atlsd.lib after I linked atls.lib. I wasn't even aware of atlsd.lib before. Can this be because of something else?Spieler
@JohnDoe, I don't have VC2008 or WinDDK, but looking at the atlbase.h that comes with VC2010, I see the following: if the project uses ATL in a dynamic library, it links to atl.lib using #pragma comment(lib, "atl.lib"). If it's a debug build, it also links to atlsd.lib, and if release to atls.lib. Not sure why the static libs are always included, but anyway - try to remove the linker dependencies, and just include atlbase.h. Let it summon the needed libs. If it doesn't find the libs, add their folder to the Additional Library Directories linker setting.Amaurosis

© 2022 - 2024 — McMap. All rights reserved.