0
votes

I am currently upgrading our source code from VS2012 to VS2019. One project which uses MFC does not link successfully:

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)"

We are building with Multi-Byte Character Set (MBCS). My first thought was, that we are missing the the mbcs libraries. But as mentioned here, the libraries are installed by default, "when you select MFC and ATL support".

I added atlbase.h in the code and added atls.lib manually as additional dependency, but that did not solve the problem.

How can I figure out which library is missing?

Edit 1: Let's take a look into 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();

As far as I see, this is one of the symbols which is not found. As can be red about the __interface keyword, it implicitly makes the functions pure virtual. These kind of linker errors might be caused by non pure virtual function declarations.

Might there be a bug which makes the functions in the __interface not pure virtual?

1
If that is the only unresolved external you get, try changing the /Zc:wchar_t compiler option. With C++, the parameter types get mangled into the symbol name. A mismatch will result in inability to find the respective symbol.IInspectable
Changed from /Zc:wchar_t to /Zc:wchar_t- and back did not solve the errorsDragoner
Added atlmem.h and atlsimpstr.h, but still having the errors. I am starting to believe that those symbols should be inside atls.lib but for whatsoever reason they are not.Dragoner
I suggest you could try to add the atls.lib. According to the DOC.When the project has a reference to a library (.LIB) or object (.OBJ) file that in turn requires symbols from another library. It may happen even if you don't call functions that cause the dependency. To fix this issue, add a reference to the other library to your project.Jeaninez - MSFT

1 Answers

0
votes

After excluding nearly all source files and commenting out a lot of functionality, I could see that the linker errors are correlated to <afxwin.h>. Moving <afxwin.h> to the top of each source files removed the linker errors. However, I am interested to know why compiling with VS2012 gives another behavior compared to VS2019.