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

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.

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.

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.

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' =)

Linking error while using Visual Studio 2005(VC8)

I am getting a bunch of linking errors while trying to link the release version of an executable(debug version does not have the same issue). Comparing the command line for the link does not reveal any issues.
there are broadly 2 types of errors neither of which I can get a handle on.
The first kind complains about a unresolved external symbol _declspec(dllimport)
As an example:
error LNK2019: unresolved external symbol
"_declspec(dllimport)
public: __thiscall
stlpd_std::basic_string,class stlpd_std::allocator >::basic_string,class stlpd_std::allocator >(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class stlpd_std::basic_string,class stlpd_std::allocator > const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z)
for a more human readable version(replacing all the strings):
error LNK2019: unresolved external symbol
"__declspec(dllimport)
public: __thiscall
string::basic_string,class stlpd_std::allocator >(class string const &)" (_imp??0?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std##QAE#ABV01##Z) referenced in function "public: __thiscall Springfield::generic::runtime_error::runtime_error(class string const &)" (??0runtime_error#generic#Springfield##QAE#ABV?$basic_string#DV?$char_traits#D#stlpd_std##V?$allocator#D#2##stlpd_std###Z
The sceond class of errors complains about
unresolved external symbol __CrtDbgReportW
I hope I can get some kind of insight in dealing with this.
From the errors it looks like you are not including the CRT as one of your linked libraries. Here is a link to the different CRT lib's offered in Visual Studio 2005. Choose the one which is most appropriate and make sure it's in the list of lib's to link against
http://msdn.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx
It looks like you're either including a file that's been built using the debug settings or you're mixing runtime libraries (DLL and static).