Unresolved external symbols when building on Windows


    Mar 15 2013 | 5:54 pm
    Hi Devs,
    I am in the process of upgrading my Max 5 - based repository to the Max 6 SDK. On Mac, now everything seems to work fine, so I just go to the evil moment when I needed to turn towards Visual Studio. Of course, things just don't work... It even took me a couple of hours to get until a point where I can give a minimal code example to illustrate what doesn't work. So, I have a file that compiles fine with the Max 5 SDK and Visual Studio. Now, I just added that single file to the 'dummy' example of Max 6. It seems that everything gets compiled fine, but then I start getting linker errors:
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) __int64 const std::_BADOFF" (__imp_?_BADOFF@std@@3_JB)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xout_of_range(char const *)" (__imp_?_Xout_of_range@std@@YAXPBD@Z)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) void __cdecl std::_Xlength_error(char const *)" (__imp_?_Xlength_error@std@@YAXPBD@Z)
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__send@16
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__closesocket@4
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__socket@12
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__bind@12
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__recv@16
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__sendto@24
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__ntohs@4
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__htons@4
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__select@20
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__htonl@4
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__inet_ntoa@4
    sadam.common.obj : error LNK2001: unresolved external symbol __imp__connect@12
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual class std::basic_streambuf > * __thiscall std::basic_streambuf >::setbuf(char *,__int64)" (__imp_?setbuf@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAEPAV12@PAD_J@Z)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual __int64 __thiscall std::basic_streambuf >::xsputn(char const *,__int64)" (__imp_?xsputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPBD_J@Z)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual __int64 __thiscall std::basic_streambuf >::xsgetn(char *,__int64)" (__imp_?xsgetn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JPAD_J@Z)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) protected: virtual __int64 __thiscall std::basic_streambuf >::showmanyc(void)" (__imp_?showmanyc@?$basic_streambuf@DU?$char_traits@D@std@@@std@@MAE_JXZ)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall std::basic_streambuf >::_Unlock(void)" (__imp_?_Unlock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall std::basic_streambuf >::_Lock(void)" (__imp_?_Lock@?$basic_streambuf@DU?$char_traits@D@std@@@std@@UAEXXZ)
    sadam.common.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::_Container_base0::_Orphan_all(void)" (__imp_?_Orphan_all@_Container_base0@std@@QAEXXZ)
    
    I have the default settings of the 'dummy' example project. However, I also tried that replacing maxcrt.lib with maxcrt_p.lib doesn't solve the problem. The weird thing is that in Max 5 I never got these errors...
    Any help would be really appreciated! Cheers, Ádám
    EDIT: I should add that I am on Visual Studio 2010, not on 2008. While one might suggest to use Visual Studio 2008, that's a way too old version, I am not even sure whether one can obtain it at all... So, I'd appreciate a suggestion that works on VS 2010...

    • Mar 19 2013 | 1:02 am
      Hi Ádám,
      First, I'd like to mention that the new Max 6.1.1 SDK provides example projects in VS2010/VS2012 format.
      To state the obvious, it looks like your errors are some kind of linking problem with C++ code. I'm not sure, but it looks like some of these mangled C++ names might be using the stdcall calling convention, whereas Max externs use the cdecl calling convention (see http://en.wikipedia.org/wiki/X86_calling_conventions for details). So maybe that explains why the symbols it is looking for cannot be found.
      You could also try to make sure that the C++ standard library is correctly set in the target settings, though I think it should usually give you something half-workable by default.
      Hope this helps!
    • Mar 19 2013 | 8:02 am
      Hi Tim,
      thanks for the reply, and +1 for the new SDK! :-)
      In the meantime, I fixed the error. It turns out that, after spending 8 hours of desperate try-and-error experiments with VS settings, it came to my mind to open the project XML file with a text editor and change the order of the settings randomly. This solved the problem (actually, when I changed the order of the files included in the project).
      A few days ago a software designer friend of mine told me that it is well known that linkers can be quite sensitive of the actual order of linking the files. I can just second that opinion...
      Cheers, Ádám
    • Mar 21 2014 | 6:11 am
      Hi Adam,
      Even i am facing the same problem from two days. can you please mention the steps u followed to solve this? it would be great help. I am new to Windows world and tried all possible things and i know its linking or name mangling issue, but couldnt really make out..
      thanks, Nagaraj
    • Mar 21 2014 | 6:14 am
      1>------ Rebuild All started: Project: xmlsam, Configuration: Debug Win32 ------ 1>Build started 3/21/2014 11:26:03 AM. 1>_PrepareForClean: 1> Deleting file "Debug\xmlsam.lastbuildstate". 1>InitializeBuildStatus: 1> Creating "Debug\xmlsam.unsuccessfulbuild" because "AlwaysCreate" was specified. 1>ClCompile: 1> XMLWrapper.cxx 1>f:\xmlsam\xmlwrapper.cxx(73): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>f:\xmlsam\xmlwrapper.cxx(107): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1>f:\xmlsam\xmlwrapper.cxx(115): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 10.0\vc\include\stdio.h(371) : see declaration of 'sprintf' 1> os.cxx 1>f:\xmlsam\os.cxx(69): warning C4101: 'iRetVal' : unreferenced local variable 1> main.cxx 1> Generating Code... 1>f:\xmlsam\os.cxx(543): warning C4700: uninitialized local variable 'iRetVal' used 1>Lib: 1> xmlsam.vcxproj -> F:\xmlsam\Debug\xmlsam.lib 1>FinalizeBuildStatus: 1> Deleting file "Debug\xmlsam.unsuccessfulbuild". 1> Touching "Debug\xmlsam.lastbuildstate". 1> 1>Build succeeded. 1> 1>Time Elapsed 00:00:01.52 2>------ Rebuild All started: Project: console, Configuration: Debug Win32 ------ 2>Build started 3/21/2014 11:26:05 AM. 2>_PrepareForClean: 2> Deleting file "Debug\console.lastbuildstate". 2>InitializeBuildStatus: 2> Touching "Debug\console.unsuccessfulbuild". 2>ClCompile: 2> stdafx.cpp 2> console.cpp 2> Generating Code... 2>main.obj : error LNK2019: unresolved external symbol "public: int __thiscall AppBase::Init(struct Chars *,int,struct Chars *,int *)" (?Init@AppBase@@QAEHPAUChars@@H0PAH@Z) referenced in function "int __cdecl prop(int,char * *)" (?prop@@YAHHPAPAD@Z) 2>main.obj : error LNK2019: unresolved external symbol "public: __thiscall AppBase::~AppBase(void)" (??1AppBase@@QAE@XZ) referenced in function "int __cdecl prop(int,char * *)" (?prop@@YAHHPAPAD@Z) 2>main.obj : error LNK2019: unresolved external symbol "public: __thiscall AppBase::AppBase(void)" (??0AppBase@@QAE@XZ) referenced in function "int __cdecl prop(int,char * *)" (?prop@@YAHHPAPAD@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__listen@8 referenced in function "int __cdecl OSSockOpenSrvr(int *,int,int *)" (?OSSockOpenSrvr@@YAHPAHH0@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__bind@12 referenced in function "int __cdecl OSSockOpenSrvr(int *,int,int *)" (?OSSockOpenSrvr@@YAHPAHH0@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__htons@4 referenced in function "int __cdecl OSSockOpenSrvr(int *,int,int *)" (?OSSockOpenSrvr@@YAHPAHH0@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__closesocket@4 referenced in function "int __cdecl OSSockOpenSrvr(int *,int,int *)" (?OSSockOpenSrvr@@YAHPAHH0@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__socket@12 referenced in function "int __cdecl OSSockOpenSrvr(int *,int,int *)" (?OSSockOpenSrvr@@YAHPAHH0@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__inet_ntoa@4 referenced in function "int __cdecl OSSockOpenIncoming(int,char * *,int *,int *)" (?OSSockOpenIncoming@@YAHHPAPADPAH1@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__accept@12 referenced in function "int __cdecl OSSockOpenIncoming(int,char * *,int *,int *)" (?OSSockOpenIncoming@@YAHHPAPADPAH1@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__connect@12 referenced in function "int __cdecl OSSockOpenClnt(bool,struct Chars *,int,int *,int *)" (?OSSockOpenClnt@@YAH_NPAUChars@@HPAH2@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__inet_pton@12 referenced in function "int __cdecl OSSockOpenClnt(bool,struct Chars *,int,int *,int *)" (?OSSockOpenClnt@@YAH_NPAUChars@@HPAH2@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__setsockopt@20 referenced in function "int __cdecl OSSetSockOptReuseAddr(int,int,int *)" (?OSSetSockOptReuseAddr@@YAHHHPAH@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__ioctlsocket@12 referenced in function "int __cdecl OSSetSockOptBlockMode(int,int,int *)" (?OSSetSockOptBlockMode@@YAHHHPAH@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__shutdown@8 referenced in function "int __cdecl OSSockClose(int,int *)" (?OSSockClose@@YAHHPAH@Z) 2>os.obj : error LNK2019: unresolved external symbol __imp__inet_addr@4 referenced in function "int __cdecl OSMcastSockOpenSrvr(bool,struct Chars *,int,int *,int *)" (?OSMcastSockOpenSrvr@@YAH_NPAUChars@@HPAH2@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Initialize(char const * const,char const * const,class xercesc_3_1::PanicHandler * const,class xercesc_3_1::MemoryManager * const)" (__imp_?Initialize@XMLPlatformUtils@xercesc_3_1@@SAXQBD0QAVPanicHandler@2@QAVMemoryManager@2@@Z) referenced in function "public: __thiscall XMLWrapper::XMLWrapper(struct Chars *)" (??0XMLWrapper@@QAE@PAUChars@@@Z) 2>XMLWrapper.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static char const * const xercesc_3_1::XMLUni::fgXercescDefaultLocale" (__imp_?fgXercescDefaultLocale@XMLUni@xercesc_3_1@@2QBDB) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLPlatformUtils::Terminate(void)" (__imp_?Terminate@XMLPlatformUtils@xercesc_3_1@@SAXXZ) referenced in function "public: __thiscall XMLWrapper::~XMLWrapper(void)" (??1XMLWrapper@@QAE@XZ) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl xercesc_3_1::XMLString::release(wchar_t * *,class xercesc_3_1::MemoryManager * const)" (__imp_?release@XMLString@xercesc_3_1@@SAXPAPA_WQAVMemoryManager@2@@Z) referenced in function "public: int __thiscall XMLWrapper::InitTable(struct Chars *,int,struct Chars * *,struct tsUDAttr *,int *)" (?InitTable@XMLWrapper@@QAEHPAUChars@@HPAPAU2@PAUtsUDAttr@@PAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static char * __cdecl xercesc_3_1::XMLString::transcode(wchar_t const * const,class xercesc_3_1::MemoryManager * const)" (__imp_?transcode@XMLString@xercesc_3_1@@SAPADQB_WQAVMemoryManager@2@@Z) referenced in function "public: int __thiscall XMLWrapper::InitTable(struct Chars *,int,struct Chars * *,struct tsUDAttr *,int *)" (?InitTable@XMLWrapper@@QAEHPAUChars@@HPAPAU2@PAUtsUDAttr@@PAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl xercesc_3_1::XMLString::equals(wchar_t const *,wchar_t const *)" (__imp_?equals@XMLString@xercesc_3_1@@SA_NPB_W0@Z) referenced in function "public: int __thiscall XMLWrapper::InitTable(struct Chars *,int,struct Chars * *,struct tsUDAttr *,int *)" (?InitTable@XMLWrapper@@QAEHPAUChars@@HPAPAU2@PAUtsUDAttr@@PAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static wchar_t * __cdecl xercesc_3_1::XMLString::transcode(char const * const,class xercesc_3_1::MemoryManager * const)" (__imp_?transcode@XMLString@xercesc_3_1@@SAPA_WQBDQAVMemoryManager@2@@Z) referenced in function "public: int __thiscall XMLWrapper::InitTable(struct Chars *,int,struct Chars * *,struct tsUDAttr *,int *)" (?InitTable@XMLWrapper@@QAEHPAUChars@@HPAPAU2@PAUtsUDAttr@@PAH@Z) 2>XMLWrapper.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class xercesc_3_1::MemoryManager * xercesc_3_1::XMLPlatformUtils::fgMemoryManager" (__imp_?fgMemoryManager@XMLPlatformUtils@xercesc_3_1@@2PAVMemoryManager@2@A) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class xercesc_3_1::DOMDocument * __thiscall xercesc_3_1::AbstractDOMParser::getDocument(void)" (__imp_?getDocument@AbstractDOMParser@xercesc_3_1@@QAEPAVDOMDocument@2@XZ) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall xercesc_3_1::AbstractDOMParser::parse(char const * const)" (__imp_?parse@AbstractDOMParser@xercesc_3_1@@QAEXQBD@Z) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall xercesc_3_1::XercesDOMParser::~XercesDOMParser(void)" (__imp_??1XercesDOMParser@xercesc_3_1@@UAE@XZ) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall xercesc_3_1::AbstractDOMParser::setLoadExternalDTD(bool)" (__imp_?setLoadExternalDTD@AbstractDOMParser@xercesc_3_1@@QAEX_N@Z) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall xercesc_3_1::AbstractDOMParser::setDoSchema(bool)" (__imp_?setDoSchema@AbstractDOMParser@xercesc_3_1@@QAEX_N@Z) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall xercesc_3_1::AbstractDOMParser::setDoNamespaces(bool)" (__imp_?setDoNamespaces@AbstractDOMParser@xercesc_3_1@@QAEX_N@Z) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall xercesc_3_1::AbstractDOMParser::setValidationScheme(enum xercesc_3_1::AbstractDOMParser::ValSchemes)" (__imp_?setValidationScheme@AbstractDOMParser@xercesc_3_1@@QAEXW4ValSchemes@12@@Z) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>XMLWrapper.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall xercesc_3_1::XercesDOMParser::XercesDOMParser(class xercesc_3_1::XMLValidator * const,class xercesc_3_1::MemoryManager * const,class xercesc_3_1::XMLGrammarPool * const)" (__imp_??0XercesDOMParser@xercesc_3_1@@QAE@QAVXMLValidator@1@QAVMemoryManager@1@QAVXMLGrammarPool@1@@Z) referenced in function "public: int __thiscall XMLWrapper::InitFile(int *)" (?InitFile@XMLWrapper@@QAEHPAH@Z) 2>F:\xmlsam\Debug\console.exe : fatal error LNK1120: 32 unresolved externals 2> 2>Build FAILED. 2> 2>Time Elapsed 00:00:00.88 ========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
    • Mar 21 2014 | 6:22 am
      i Have a static library which compiles and builds fine, code is written using c/c++. and i have a Console app which uses Static library "xmlsam.lib" as reference. is there something that i can do ?
    • May 15 2017 | 1:12 pm
      Dear all,
      this is a pretty old thread, but since I got exactly the same problem and spent some hours to find the solution, I found relevant to share my experience:
      The problem comes from the fact that in Release mode (not in debug), the SDK (ext_prefix.h) does not link with the standard C/C++ runtime libraries provided by Microsoft (msvcrt.lib and msvcprt.lib), but with custom versions provided with the SDK (maxcrt.lib and maxcrt_p.lib). If the object has to be linked with external libraries that where build with msvcrt.lib or msvcprt.lib, this may lead to definition mismatches and linking errors.
      The solution is to add the preprocessor macro MAXAPI_USE_MSCRT, as documented here: https://cycling74.com/forums/vs-version-problems-when-releasing-objects-for-windows-using-visual-studio/
      Hope that helps,
      Alexis