Unresolved external symbol ATL::IAtlMemMgr after upgrading to Visual Studio 2019 - mfc

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?

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.

Related

Building and Linking V8 in Visual Studio

I'm having a really hard time trying to figure out how to build Google's V8 on Windows.
So far I have:
Installed depot_tools
Fetched v8: fetch v8
Created the project files: gn gen --ide=vs2015 out/Default
Built the entire solution in VS2015
My issue is that this only produces a large number of .obj files and no .lib files.
I have set the projects (v8, v8_base, v8_libbase, etc.) to Configuration type: Static library (.lib):
I'm not sure how to get Visual Studio to generate the library files. Any help appreciated!
Update
I have managed to produce library files using the following steps:
Open VS Developer Command Line
Navigate to the directories containing obj files for v8_base, v8_libbase, v8_external_snapshot and v8_libplatform.
For each of these, build a .lib manually using the lib command e.g. lib /o:v8_base *.obj
Copy all these lib files into a directory along with icui18n.lib and icuuc.lib (these were created fine during the build.)
I'm now trying to actually use the libraries and have a new problem which I would appreciate help with.
I have linked the following libraries in VS: v8_base.lib; v8_libbase.lib; v8_external_snapshot.lib; v8_libplatform.lib; icui18n.lib; icuuc.lib; winmm.lib;, however I am having an issue with a few unresolved symbols:
unresolved external symbol "public: static void __cdecl v8::sampler::Sampler::TearDown(void)" (?TearDown#Sampler#sampler#v8##SAXXZ) referenced in function "public: static void __cdecl v8::internal::V8::TearDown(void)" (?TearDown#V8#internal#v8##SAXXZ) TriviaBot v8_base.lib(v8.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::Stop(void)" (?Stop#Sampler#sampler#v8##QEAAXXZ) referenced in function "private: void __cdecl v8::internal::Isolate::Deinit(void)" (?Deinit#Isolate#internal#v8##AEAAXXZ) v8_base.lib(isolate.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::Stop(void)" (?Stop#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: __cdecl v8::sampler::Sampler::Sampler(class v8::Isolate *)" (??0Sampler#sampler#v8##QEAA#PEAVIsolate#2##Z) referenced in function "public: __cdecl v8::internal::Ticker::Ticker(class v8::internal::Isolate *,int)" (??0Ticker#internal#v8##QEAA#PEAVIsolate#12#H#Z) v8_base.lib(log.obj)
unresolved external symbol "public: __cdecl v8::sampler::Sampler::Sampler(class v8::Isolate *)" (??0Sampler#sampler#v8##QEAA#PEAVIsolate#2##Z) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: virtual __cdecl v8::sampler::Sampler::~Sampler(void)" (??1Sampler#sampler#v8##UEAA#XZ) referenced in function "public: virtual void * __cdecl v8::internal::Ticker::`scalar deleting destructor'(unsigned int)" (??_GTicker#internal#v8##UEAAPEAXI#Z)
unresolved external symbol "public: virtual __cdecl v8::sampler::Sampler::~Sampler(void)" (??1Sampler#sampler#v8##UEAA#XZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::Start(void)" (?Start#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: void __cdecl v8::internal::Profiler::Engage(void)" (?Engage#Profiler#internal#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::IncreaseProfilingDepth(void)" (?IncreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: void __cdecl v8::internal::Profiler::Engage(void)" (?Engage#Profiler#internal#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::IncreaseProfilingDepth(void)" (?IncreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DecreaseProfilingDepth(void)" (?DecreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: void __cdecl v8::internal::Profiler::Disengage(void)" (?Disengage#Profiler#internal#v8##QEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DecreaseProfilingDepth(void)" (?DecreaseProfilingDepth#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DoSample(void)" (?DoSample#Sampler#sampler#v8##QEAAXXZ) referenced in function "public: virtual void __cdecl v8::internal::SamplingThread::Run(void)" (?Run#SamplingThread#internal#v8##UEAAXXZ) v8_base.lib(log.obj)
unresolved external symbol "public: void __cdecl v8::sampler::Sampler::DoSample(void)" (?DoSample#Sampler#sampler#v8##QEAAXXZ) v8_base.lib(cpu-profiler.obj)
unresolved external symbol "public: static void __cdecl v8::sampler::Sampler::SetUp(void)" (?SetUp#Sampler#sampler#v8##SAXXZ) referenced in function "private: static void __cdecl v8::internal::V8::InitializeOncePerProcessImpl(void)" (?InitializeOncePerProcessImpl#V8#internal#v8##CAXXZ) v8_base.lib(v8.obj)
All of the error seem to be related to v8::sampler - any help is again appreciated!
And it looks like I'm answering my own question again. I hope the info I listed in the question will be useful for anyone who struggles with the out-of-date documentation like me.
My update covers everything required except for the fact I didn't even notice the v8_libsampler project and forgot to generate the library file for it. Once I did that and linked it, I was up and running!
Just like you, I was trying different settings to get the lib building. And here are my steps:
After gn gen, run gn args out/Default, uncomment is_component_build, that's the equivalent of component=shared_library I guess.
While I also have problem building all.sln in vs.net I realized msbuild can give me some of the dll/lib files.
Good luck.
I have done similar config but for VS2013 and runned ninja to build everything. Build has produced me set of DLLs, including v8.dll, which I am completely fine with.

XDispatch C++ Unresolved Externals

I'm work with GCD in C++ with xdisptach, libdispatch in Visual Studio 2012 on Windows 7.
I am declaring a class with a global variable that is a dispatch queue. Other functions in the class call the queue's function. Everything compiles fine, except when i instantiate the queue in the constructor.
xdispatch::queue* dispatch_queue;
AsyncNode()
{
dispatch_queue = new xdispatch::queue(Name);
}
When dispatch_queue = new xdispatch::queue(Name); is commented out, it all compiles fine. Otherwise i get the following errors.
Error 50 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall xdispatch::queue::~queue(void)" (__imp_??1queue#xdispatch##UAE#XZ) referenced in function "public: virtual void * __thiscall xdispatch::queue::`scalar deleting destructor'(unsigned int)" (??_Gqueue#xdispatch##UAEPAXI#Z)
Error 49 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall xdispatch::queue::queue(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0queue#xdispatch##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall AsyncNode::AsyncNode(void)" (??0AsyncNode##QAE#XZ)
Error 53 error LNK2001: unresolved external symbol "public: virtual void __thiscall xdispatch::object::resume(void)" (?resume#object#xdispatch##UAEXXZ)
Error 51 error LNK2001: unresolved external symbol "public: virtual void * __thiscall xdispatch::queue::native(void)const " (?native#queue#xdispatch##UBEPAXXZ)
Error 52 error LNK2001: unresolved external symbol "public: virtual struct dispatch_queue_s * __thiscall xdispatch::queue::native_queue(void)const " (?native_queue#queue#xdispatch##UBEPAUdispatch_queue_s##XZ)
This is the main site for xdispatch, but i can't find anything in terms of a forum or help with xdispatch in particular. There are many for objective-c.... :/
http://opensource.mlba-team.de/xdispatch/docs/current/index.html
First of all, the behavior regarding deleting the "problematic" line is normal - when you're defining a pointer you're not invoking any function, and that is the reason you are not getting the "unresolved external errors".
When you're initializing the variable by calling the constructor, you then run into problems because you're trying to call a function which is not available at link time.
When working with external libraries using DLLs, you must link to the appropriate import libraries, usually supplied as "lib" files. In your case, there is a folder named "lib" in the zip package. Also, the DLLs must availble at run-time - by putting them in the folder of the executable, or adding them to the PATH environment variable.
In order to link to a library, follow these steps (taken from MSDN):
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.

Strange LNK2001 linker error

Yesterday I got this linker error. I have searched on google and msdn without success.
My problem:
I have moved some parts of my cpp project in a extern static library. I added the h file to my main project and added the dependencies to the lib files. Unfortunately I get a lot linker errors.
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *)" (?Find#CFileInfo#NFind#NFile#NWindows##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: class NWindows::NCOM::CPropVariant & __thiscall NWindows::NCOM::CPropVariant::operator=(unsigned short const *)" (??4CPropVariant#NCOM#NWindows##QAEAAV012#PBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CInFileStream::Open(unsigned short const *)" (?Open#CInFileStream##QAE_NPBG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NFile::NIO::COutFile::Create(unsigned short const *,bool)" (?Create#COutFile#NIO#NFile#NWindows##QAE_NPBG_N#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "void __cdecl ConvertUInt32ToString(unsigned int,unsigned short *)" (?ConvertUInt32ToString##YAXIPAG#Z)
1>Compressor.obj : error LNK2001: unresolved external symbol "public: bool __thiscall NWindows::NDLL::CLibrary::Load(unsigned short const *)" (?Load#CLibrary#NDLL#NWindows##QAE_NPBG#Z)
All this methods a part of my extern lib. I have tries a lot of compiler settings without success.
Further more when I remove the lib dependencie completely from the linker I get 26 LNK2001 error. So the linker finds only "parts" of the lib.
Do I use a wrong compiler / linker option for my projects?
edit:
The problem was the parameter define LPCTSTR of the method CLibrary::Load(LPCTSTR fileName). In my lib I set the option "Treat wchar_t as build-in type (Properties->C/C++->Lanuage-> ... ) to No. And now it works.
There's not enough information in the question so my answer merely serves as a guide.
Take one function, for instance bool NWindows::NFile::NFind::CFileInfo::Find(unsigned short const *) and find definition of it in your code. Is it there? With this exact function signature? Is it in unnamed namespace? Is it declared static in source file?
Also, try full rebuild of everything. You'd be surprised how many times full rebuild makes mysterious problems go away.

Linker generates LNK2001 (( try to make unmanaged c++ dll in vs 2010

Error 10 error LNK2001: unresolved external symbol "public: virtual void __thiscall MPPostProcess::prepareForProcess(void)" (?prepareForProcess#MPPostProcess##UAEXXZ) D:\Prj\MagicLib\MagicLib\dllmain.obj MagicLib
Error 11 error LNK2001: unresolved external symbol "public: virtual void __thiscall MPPostProcess::prepareForProcess(void)" (?prepareForProcess#MPPostProcess##UAEXXZ) D:\Prj\MagicLib\MagicLib\MPImageData.obj MagicLib
Error 12 error LNK2019: unresolved external symbol "private: virtual __thiscall PPBlackAndWhite::~PPBlackAndWhite(void)" (??1PPBlackAndWhite##EAE#XZ) referenced in function "private: virtual void * __thiscall PPBlackAndWhite::`scalar deleting destructor'(unsigned int)" (??_GPPBlackAndWhite##EAEPAXI#Z) D:\Prj\MagicLib\MagicLib\dllmain.obj MagicLib
How to cure this?
There are 2 likely candidates for unresolved external errors:
If you defined the MPPostProcess class, then you have probably forgot to provide an implementation for the prepareForProcess(void) and ~PPBlackAndWhite(void) functions.
If the MPPostProcess class is a class you are using provided by an external library, then you need to link to the library that provides those functions
You probably haven't provided definitions for prepareForProcess() or ~PPBlackAndWhite().

VC++ linker errors on std::exception::_Raise and std::exception::exception

I am using Visual C++ 2005 Express Edition and get the following linker errors:
19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise#exception#std##QBEXXZ) referenced in function "protected: static void __cdecl std::vector<class mytype,class std::allocator<class mytype> >::_Xlen(void)" (?_Xlen#?$vector#Vmytype##V?$allocator#Vmytype###std###std##KAXXZ)
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise#exception#std##QBEXXZ)
19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_??0exception#std##QAE#PBDH#Z) referenced in function "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0logic_error#std##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##1##Z)
19>mylib2.lib(mylibsource2.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::exception::exception(char const *,int)" (__imp_??0exception#std##QAE#PBDH#Z)
I turned off exceptions in generated code, and I am using before including the vector header file:
#define _HAS_EXCEPTIONS 0
A few Google results turned up some stuff, but no "aha!" solutions that worked for me.
EDIT:
As noted "_HAS_EXCEPTIONS 0" doesn't turn off exceptions, per se. What it does is, at least in the vector header file, is call _Raise on an exception object instead of calling the C++ "throw". In my case, it can't link to the exception object's _Raise function since I am not including the correct library. What that library is, though, is not obvious.
Adding this line:
#define _STATIC_CPPLIB
before including the vector header seems to do the trick.
The third error makes it clear that #define the _HAS_EXCEPTIONS 0 does not affect . Now, might include (makes sense, sharing code might reduce the size of your executable). That would explain why you still have errors if you define it before your inclusion of . This kind of defines should be done in your project settings.
Note that _HAS_EXCEPTIONS is an unsupported feature in Visual Studio. It does not turn off exceptions as such.