C++ VS2010 Unresolved symbol - c++

I really hate this problem that the compiler tells me
"err LNK2019: Reference to unresolved external symbol".
Unlike other compiler errors, I can not jump to this problem by double-clicking it.
It always takes me a tremendous amount of time to figure out what I did wrong.
For example, from the error message
Error 9 error LNK2019: Reference to unresolved symbol ""public: class std::vector<unsigned char,class std::allocator<unsigned char> > & __thiscall clsJoinBigUnsignedCharMap::Content(void)" (?Content#clsJoinBigUnsignedCharMap##QAEAAV?$vector#EV?$allocator#E#std###std##XZ)" in Funktion ""private: void __thiscall CCompiler::pSerializeJoinBigUnsignedCharMap(class clsJoinBigUnsignedCharMap &,struct _iobuf *)" (?pSerializeJoinBigUnsignedCharMap#CCompiler##AAEXAAVclsJoinBigUnsignedCharMap##PAU_iobuf###Z)". m:\compiler.obj voice
I can not see at all where I should look for the error.
Am I missing something here? I don't see where the error is located, and the fact that I can not jump to the problem by double-clicking it indicates to me that VS2010 does not know either.
Thank you for the help.

Your CCompiler::pSerializeJoinBigUnsignedCharMap (from compiler.obj) is using a method (clsJoinBigUnsignedCharMap::Content()) that's defined in a header, but not implemented within any of the linked source files.

If you read the message it says:
in Funktion ""private: void __thiscall CCompiler::pSerializeJoinBigUnsignedCharMap(class clsJoinBigUnsignedCharMap &,struct _iobuf *)"
so in the function CCompiler::pSerializeJoinBigUnsignedCharMap,
there is a unreferenced symbol
clsJoinBigUnsignedCharMap::Content(void)
the linker cannot link with clsJoinBigUnsignedCharMap::Content, it has no compiled code for it.

Related

C++ Using External .lib file - error LNK2019: unresolved external symbol

I am a newbie in C++ and getting the below error while compiling an old C++ application. On reading various posts here, my understanding is that the function call might be missing some parameters. Now, the function is a part of static library. How do I identify the missing parameters? Or is (enough) required information there in the error message below?
rfcclass.lib(crfcglob.obj) : error LNK2019: unresolved external symbol
"class std::basic_ostream > & __cdecl std::operator<<(class
std::basic_ostream > &,char const *)"
(??6std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
referenced in function "public: __thiscall
CRfcTrace::~CRfcTrace(void)" (??1CRfcTrace##QAE#XZ)
Thanks.

cppcms lots of unresolved external symbols

I am having errors as follows trying to build cppcms.
Error 184 error LNK2019: unresolved external symbol __imp_pcre_compile referenced in function "public: void __cdecl booster::regex::assign(class std::basic_string,class std::allocator > const &,int)" (?assign#regex#booster##QEAAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) C:\Stuff\Development\CPP\cppcms-1.0.2\build\booster\pcre_regex.obj
Error 185 error LNK2019: unresolved external symbol __imp_pcre_exec referenced in function "public: bool __cdecl booster::regex::match(char const *,char const *,class std::vector,class std::allocator > > &,int)const " (?match#regex#booster##QEBA_NPEBD0AEAV?$vector#U?$pair#HH#std##V?$allocator#U?$pair#HH#std###2##std##H#Z) C:\Stuff\Development\CPP\cppcms-1.0.2\build\booster\pcre_regex.obj
Error 186 error LNK2019: unresolved external symbol __imp_pcre_fullinfo referenced in function "public: void __cdecl booster::regex::assign(class std::basic_string,class std::allocator > const &,int)" (?assign#regex#booster##QEAAXAEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) C:\Stuff\Development\CPP\cppcms-1.0.2\build\booster\pcre_regex.obj
Error 187 error LNK2019: unresolved external symbol __imp_pcre_malloc referenced in function "public: __cdecl booster::regex::data::data(struct booster::regex::data const &)" (??0data#regex#booster##QEAA#AEBU012##Z) C:\Stuff\Development\CPP\cppcms-1.0.2\build\booster\pcre_regex.obj
Error 188 error LNK2019: unresolved external symbol __imp_pcre_free referenced in function __catch$??0data#regex#booster##QEAA#AEBU012##Z$0 C:\Stuff\Development\CPP\cppcms-1.0.2\build\booster\pcre_regex.obj
Error 189 error LNK2019: unresolved external symbol __imp_htons referenced in function "public: __cdecl booster::aio::endpoint::endpoint(class std::basic_string,class std::allocator > const &,int)" (??0endpoint#aio#booster##QEAA#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) C:\Stuff\Development\CPP\cppcms-1.0.2\build\booster\endpoint.obj
My environment is Windows 7 64 bit, using Visual Studio 2012 Professional, and CMake 2.8.9.
For everything I compile, I configure CMake to generate solutions for VS2012 to use the 64 bit compiler. When I do compile the libraries, I compile the release versions.
First I compile Zlib 1.2.7 without a problem.
Second I compile pcre-8.31 without a problem.
Then when it gets time to compile cppcms-1.0.2 I get a bunch or errors as I pointed out before. When configuring cppcms in CMake, I have my PYTHON 2.7 set, I use C:/Stuff/Development/CPP/Zlib/zlib-1.2.7/build for my ZLIB_INCLUDE_DIR, and just append a /Release/zlibstatic.lib at the end of that and you have the ZLIB library I am using, but I am not sure if I have my PCRE set up correctly.
Being that PCRE has an include and include2 in CMake, I wasn't sure what to put in them so I just did the pcre-8.31 root directory, and the pcre-8.31 build directory. For PCRE_LIB I use pcre-8.31/build/Release/pcre.lib.
I have deleted all of the build directories for the libraries and started over again even, but I still have these issues and I am not sure what could be causing them. Later I realized the booster inside of the cppcms build directory also has a solution, so I built that first, which had 3 failed projects, but most succeeded, however it didn't make a difference for cppcms building.
If you have any more questions about what I was doing, please ask and I will edit them in.
The best place to ask questions about cppcms is in the cppcms mailing list. Sign up here:
https://lists.sourceforge.net/lists/listinfo/cppcms-users
Artyom is providing an excellent support service there. Although he is also a S.O. member, not all cppcms developers are, and many of them also provide help on the mailing list. Overall, you'll get better answers there, especially since the people who are able to answer will more quickly notice your question.

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.

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

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.