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

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().

Related

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

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.

Linker error when user defined dll is refering another userdefined dll

I was trying to implement a protocol stack using Protocol Layer Design Pattern :
http://www.eventhelix.com/realtimemantra/patterncatalog/protocol_layer.htm
In our project,I have all the layers as separate dlls.
The layers that i have are:
Application Layer dll
LLC Layer dll
MAC Layer dll
Physical Layer dll
I have another project in the same solution which implements the Design Pattern and
has the implementations of the General functionalities of a protocol Layer.
All my layers are inheriting from the Protocol Layer Base class. The dependency between
projects is as follows:
Protocol Layer Design Pattern dll: No dependency
Physical Layer dll: Protocol Design Pattern dll
MAC Layer dll: Protocol Design Pattern dll and Physical Layer dll
LLC Layer dll: Protocol Design Pattern dll and MAC Layer dll
Application Layer dll: Protocol Design Pattern dll and LLC Layer dll
Based on the design pattern, each of our layer has pointers to the layer above and below it.
And the flow that we designed is like: In application layer constructor we create an object of
LLC Layer then LLC Layer creates Mac layer and MAC layer inturn creates physical Layer. They all are linked
using pointers.
My Protocol Design Pattern project dll and Physical Layer dll builds properly. But other dll builds are giving
linker error. Saying unresolved externals to the constructor of the underlying layer.
These are the errors which i am getting.
==================================
1>phLayer.obj : error LNK2019: unresolved external symbol "public:
virtual __thiscall CProtocolLayer::~CProtocolLayer(void)"
(??1CProtocolLayer##UAE#XZ) referenced in function
__unwindfunclet$??0CPhysicalLayer##QAE#PAVCProtocolLayer###Z$0 1>phLayer.obj : error LNK2019: unresolved external symbol "public:
__thiscall CReceiveProtocolHandler::CReceiveProtocolHandler(class CProtocolLayer *)"
(??0CReceiveProtocolHandler##QAE#PAVCProtocolLayer###Z) referenced
in function "public: __thiscall
CPhysicalLayer::CPhysicalLayer(class CProtocolLayer *)"
(??0CPhysicalLayer##QAE#PAVCProtocolLayer###Z) 1>phLayer.obj :
error LNK2019: unresolved external symbol "public: __thiscall
CTransmitProtocolHandler::CTransmitProtocolHandler(class
CProtocolLayer *)"
(??0CTransmitProtocolHandler##QAE#PAVCProtocolLayer###Z) referenced
in function "public: __thiscall CPhysicalLayer::CPhysicalLayer(class
CProtocolLayer *)" (??0CPhysicalLayer##QAE#PAVCProtocolLayer###Z)
1>phLayer.obj : error LNK2019: unresolved external symbol "public:
__thiscall CProtocolLayer::CProtocolLayer(class CProtocolLayer *,class CProtocolLayer *)" (??0CProtocolLayer##QAE#PAV0#0#Z) referenced in function "public: __thiscall
CPhysicalLayer::CPhysicalLayer(class CProtocolLayer *)"
(??0CPhysicalLayer##QAE#PAVCProtocolLayer###Z) 1>phLayer.obj : error
LNK2019: unresolved external symbol "public: int __thiscall
CProtocolPacket::getBodyLength(void)"
(?getBodyLength#CProtocolPacket##QAEHXZ) referenced in function
"public: virtual void __thiscall CPhysicalLayer::Data_req(class
CProtocolPacket *)"
(?Data_req#CPhysicalLayer##UAEXPAVCProtocolPacket###Z) 1>phLayer.obj
: error LNK2019: unresolved external symbol "public: void __thiscall
CReceiveProtocolHandler::Handle_Receive(class CProtocolPacket *)"
(?Handle_Receive#CReceiveProtocolHandler##QAEXPAVCProtocolPacket###Z)
referenced in function "private: void __thiscall
CPhysicalLayer::dataRead(void)" (?dataRead#CPhysicalLayer##AAEXXZ)
1>phLayer.obj : error LNK2019: unresolved external symbol "public:
void __thiscall CProtocolPacket::AddTrailer(int,char *)"
(?AddTrailer#CProtocolPacket##QAEXHPAD#Z) referenced in function
"private: class CProtocolPacket __thiscall
CPhysicalLayer::convertToProtocolPacket(class
std::basic_string,class
std::allocator >)"
(?convertToProtocolPacket#CPhysicalLayer##AAE?AVCProtocolPacket##V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>phLayer.obj : error LNK2019: unresolved external symbol "public:
void __thiscall CProtocolPacket::AddHeader(int,char *)"
(?AddHeader#CProtocolPacket##QAEXHPAD#Z) referenced in function
"private: class CProtocolPacket __thiscall
CPhysicalLayer::convertToProtocolPacket(class
std::basic_string,class
std::allocator >)"
(?convertToProtocolPacket#CPhysicalLayer##AAE?AVCProtocolPacket##V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
How are you building the exe? I see that, you are facing only linker issues. Either you must be linking in the wrong order or there must be something, which went wrong. Try to link them in a correct order. This should solve the problem. If not, please provide more information.

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.

Bullet Physics Engine static library installation issues

hey so i just downloaded bullet 2.78, and took the following steps:
unziped and found this tutorial
followed the steps exactly for Cmake, except i found the pictures in the tutorial had some things checked like INSTALL LIBS and i didn't so I ended up checking EVERYTHING possible.
Went into the newly generated BULLET_PHYSICS.vcxproj and built it under debug and release
Saw i had a bunch of new libs in the lib folder in msvn/BulletBuild/lib but did nothing with them
Followed the rest of the steps in the tutorial exactly for setting up the actual project
Tried to build the last line of code: FAIL
Wondered Do i NEED the dlls, because only .libs and pdbs showed up in the lib folder, and the tutorial didn't mention em
My only experience in rebuilding libraries is through SFML by building its msvn files included in the download and using the resulting dynamic lib and dll files. The instructions in the tutorial are very different however. (If someone could explain to me how this works it would be GREAT)
I followed the instructions exactly, multiple times but i'm not sure what i'm missing. The build works if i comment out the line of code in main but keep the include, but when i keep it i get this:
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "void * __cdecl btAlignedAllocInternal(unsigned int,int)" (?btAlignedAllocInternal##YAPAXIH#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "void __cdecl btAlignedFreeInternal(void *)" (?btAlignedFreeInternal##YAXPAX#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btConvexInternalShape::getAabbSlow(class btTransform const &,class btVector3 &,class btVector3 &)const " (?getAabbSlow#btConvexInternalShape##UBEXABVbtTransform##AAVbtVector3##1#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall btCollisionShape::serialize(void *,class btSerializer *)const " (?serialize#btCollisionShape##UBEPBDPAXPAVbtSerializer###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: __thiscall btPolyhedralConvexShape::btPolyhedralConvexShape(void)" (??0btPolyhedralConvexShape##QAE#XZ)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall btPolyhedralConvexShape::~btPolyhedralConvexShape(void)" (??1btPolyhedralConvexShape##UAE#XZ)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btConvexInternalShape::setLocalScaling(class btVector3 const &)" (?setLocalScaling#btConvexInternalShape##UAEXABVbtVector3###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btCollisionShape::getBoundingSphere(class btVector3 &,float &)const " (?getBoundingSphere#btCollisionShape##UBEXAAVbtVector3##AAM#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall btCollisionShape::getAngularMotionDisc(void)const " (?getAngularMotionDisc#btCollisionShape##UBEMXZ)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual float __thiscall btCollisionShape::getContactBreakingThreshold(float)const " (?getContactBreakingThreshold#btCollisionShape##UBEMM#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btCollisionShape::serializeSingleShape(class btSerializer *)const " (?serializeSingleShape#btCollisionShape##UBEXPAVbtSerializer###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btBoxShape::getAabb(class btTransform const &,class btVector3 &,class btVector3 &)const " (?getAabb#btBoxShape##UBEXABVbtTransform##AAVbtVector3##1#Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall btBoxShape::calculateLocalInertia(float,class btVector3 &)const " (?calculateLocalInertia#btBoxShape##UBEXMAAVbtVector3###Z)
1>BulletTestApp.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall btPolyhedralConvexShape::initializePolyhedralFeatures(void)" (?initializePolyhedralFeatures#btPolyhedralConvexShape##UAE_NXZ)
1>C:\Libraries and Headers\Bullet\bullet-2.78\msvc\BulletTestApp\Release\BulletTestApp.exe : fatal error LNK1120: 14 unresolved externals
I know there's a link problem somewhere but i followed the instructions exactly so i don't know how to fix it. I don't see any additional dependencies when looking at the properties of the added projects if that's not how it's supposed to be... but I guess i don't understand this method of using a library in the first place though so that knowledge would help.
Alright, so apparently right clicking my TestBulletApp project and clicking 'Project Dependencies' was where i went wrong. msVS++ 2010 left the option there for some reason even though it
doesn't work to do it that way.
Instead to make the project dependent on the other projects in the solution you have to right click on your project like my "TestBulletApp" and go to Properties->Common Properties->Framework and References->Add New Reference" and add the depended on static library projects already added to the sollution such as 'bulletCollision' or whatever; also check that "Link Library Dependencies" is True on the right hand side.
So yeah thanks for the heads up guys..... 'cough' 'cough' =)

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.