From duncan.to at lazybugstudio.com Fri Nov 2 10:08:50 2018 From: duncan.to at lazybugstudio.com (Duncan To) Date: Fri, 2 Nov 2018 18:08:50 +0800 Subject: [swift-users] Compile debug mode DLL build by VC2015 issues Message-ID: Hello, I tried to use Swiften SDK (GIT tag version 4.0.2) in windows platform. I compiled it by Visual C++ 2015 (vc140) as debug DLL build by using the following config.py debug=1 optimize=0 set_iterator_debug_level=0 cxxflags=["/bigobj"] swiften_dll=1 There are some linker errors when compile DLL debug mode. LINK Documentation\SwiftenDevelopersGuide\Examples\EchoBot\EchoBot0x.exe Swiften_Boost.lib(error_code.obj) : error LNK2005: "public: struct std::_Container_proxy * __thiscall std::allocator::allocate(unsigned int)" (?allocate@ ?$allocator at U_Container_proxy@std@@@std@@QAEPAU_Container_proxy at 2@I at Z) already defined in Swiften4.lib(Swiften4.dll) Swiften_Boost.lib(error_code.obj) : error LNK2005: "public: void __thiscall std::allocator::deallocate(struct std::_Container_proxy *,unsigned int)" (?deallocate@ ?$allocator at U_Container_proxy@std@@@std@@QAEXPAU_Container_proxy at 2@I at Z) already defined in Swiften4.lib(Swiften4.dll) Documentation\SwiftenDevelopersGuide\Examples\EchoBot\EchoBot0x.exe : fatal error LNK1169: one or more multiply defined symbols found scons: *** [Documentation\SwiftenDevelopersGuide\Examples\EchoBot\EchoBot0x.exe] Error 1169 After some investigations, the error is realted to the template class SafeAllocator is DLL exported. While Swiften SDK instantiated it together with the base class by std::vector > and std::vector > in vector file in VC void _Alloc_proxy() { // construct proxy typename _Alty::template rebind<_Container_proxy>::other _Alproxy(_Getal()); _Myproxy() = _Unfancy(_Alproxy.allocate(1)); _Alproxy.construct(_Myproxy(), _Container_proxy()); _Myproxy()->_Mycont = &_Get_data(); } It seems most likely that SafeAllocator is instantiated in the above code when _ITERATOR_DEBUG_LEVEL != 0 Please note that I modify Sconscript.boot with flag "/MDd" when debug option enabled in order to compile a real debug mode SDK. (Setting up /MDd is not supported in the script in version 4.0.2 yet) Default _ITERATOR_DEBUG_LEVEL is 2 when /MDd is set. After resolve the above issue, another issues are found that undefined symbols appear. It is because the template class GenericRequest is __declarspec(dllimport) in the caller program; however, the template class does not instantiated by the Swiften SDK. Creating library Sluift\dll\sluift.lib and object Sluift\dll\sluift.exp client.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::shared_ptr __cdecl Swift::SetRosterRequest::create(class std::shared_ptr,class Swift::IQRouter *)" (__imp_?create at SetRosterRequest@Swift@@SA?AV?$shared_ptr at VSetRosterRequest @Swift@@@std@@V?$shared_ptr at VRosterPayload@Swift@@@4 at PAVIQRouter@2@@Z) referenced in function __catch$?Client_get_next_event_wrapper@ @YAHPAUlua_State@@@Z$0 client.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Swift::GenericRequest::GenericRequest(enum Swift::IQ::Type,class Swift::JID const &,class std::shared_ptr,class Swift::IQRouter *)" (__imp_??0?$GenericRequest at VPayload@Swift@@@Swift@@QAE at W4Type@IQ at 1@ABVJID at 1 @V?$shared_ptr at VPayload@Swift@@@std@@PAVIQRouter at 1@@Z) referenced in function "public: __thiscall std::_Ref_count_obj >::_Ref_count_obj > &,class Swift::IQRouter *>(enum Swift::IQ::Type &,class Swift::JID &,class std::shared_ptr &,class Swift::IQRouter * &&)" (??$?0AAW4Type at IQ@Swift@@AAVJID at 2@AAV?$shared_ptr at VPayload@Swift@@@std@ @PAVIQRouter at 2@@?$_Ref_count_obj at V?$GenericRequest at VPayload@Swift@@@Swift@ @@std@@QAE at AAW4Type@IQ at Swift@@AAVJID at 4@AAV?$shared_ptr at VPayload@Swift@@@1@ $$QAPAVIQRouter at 4@@Z) client.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Swift::GenericRequest::~GenericRequest(void)" (__imp_??1?$GenericRequest at VPayload@Swift@@@Swift@ @UAE at XZ) referenced in function "public: virtual void * __thiscall Swift::GenericRequest::`scalar deleting destructor'(unsigned int)" (??_G?$GenericRequest at VPayload@Swift@@@Swift@ @UAEPAXI at Z) component.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Swift::GenericRequest::~GenericRequest(void)" (__imp_??1?$GenericRequest at VPayload@Swift@@@Swift@ @UAE at XZ)client.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall Swift::GenericRequest::handleResponse(class std::shared_ptr,class std::shared_ptr)" (?handleResponse@?$GenericRequest at VPayload@Swift@@@Swift@ @UAEXV?$shared_ptr at VPayload@Swift@@@std@@V?$shared_ptr at VErrorPayload@Swift@ @@4@@Z)component.obj : error LNK2001: unresolved external symbol "public: virtual void__thiscall Swift::GenericRequest::handleResponse(class std::shared_ptr,class std::shared_ptr)" (?handleResponse@?$GenericRequest at VPayload@Swift@@@Swift@ @UAEXV?$shared_ptr at VPayload@Swift@@@std@@V?$shared_ptr at VErrorPayload@Swift@ @@4@@Z)component.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Swift::GenericRequest::GenericRequest(enum Swift::IQ::Type,class Swift::JID const &,class Swift::JID const &,class std::shared_ptr,class Swift::IQRouter *)" (__imp_??0?$GenericRequest at VPayload@Swift@@@Swift@@QAE at W4Type@IQ at 1@ABVJID at 1 @1V?$shared_ptr at VPayload@Swift@@@std@@PAVIQRouter at 1@@Z) referenced in function "public: __thiscall std::_Ref_count_obj >::_Ref_count_obj > &,class Swift::IQRouter *>(enum Swift::IQ::Type &,class Swift::JID &,class Swift::JID &,class std::shared_ptr &,class Swift::IQRouter * &&)" (??$?0AAW4Type at IQ@Swift@@AAVJID at 2@AAV32 at AAV ?$shared_ptr at VPayload@Swift@@@std@@PAVIQRouter at 2@@?$_Ref_count_obj at V ?$GenericRequest at VPayload@Swift@@@Swift@@@std@@QAE at AAW4Type@IQ at Swift @@AAVJID at 4@1AAV?$shared_ptr at VPayload@Swift@@@1@$$QAPAVIQRouter at 4@@Z)Sluift\dll\sluift.dll : fatal error LNK1120: 5 unresolved externals scons: *** [Sluift\dll\sluift.dll] Error 1120 scons: building terminated because of errors. My solution is to comment the SEIFTEN_API template class /*SWIFTEN_API*/ GenericRequest : public Request { the caller will instantiate the class when seeing the header file For the another undefined symbols, it seems that the inline static function SetRosterRequest::create is not compiled to the Swiften. This class is also declared as DLL export. My solution is to create a cpp file for SetRosterRequest and put all the function implementation to the cpp file. After that, adding SetRosterRequest.cpp entry to Swiften/Sconscript file to compile the cpp file. The motivation for me to use a DLL build instead of the default static link library is that I found that it takes a very long time for the linker to link with the debug mode static library, which is inconvience for me to have application development that link against Swiften SDK. Should you have any suggested solutions for the above issues, please tell me. Thanks, Duncan TO -------------- next part -------------- An HTML attachment was scrubbed... URL: