
Thanks for the help but I don't quite follow:
A) Isn't the point of using the polymorphic types is to avoid
instantiating all the types explicitly (at the cost of
performance/virtual function calls)?
Anyway I can't seem to instantiate the polymorphic_xml_oarchive
explicitly without getting linker errors:
#include "boost/archive/polymorphic_xml_oarchive.hpp"
template void __declspec(dllexport)
Base::serialize(boost::archive::polymorphic_xml_oarchive& ar, const
unsigned int version);
BOOST_CLASS_EXPORT_IMPLEMENT(Base);
1>Base.obj : error LNK2019: unresolved external symbol "public: static
bool __cdecl boost::archive::detail::archive_serializer_map
::insert(class boost::archive::detail::basic_serializer const *)" (?insert@?$archive_serializer_map@V?$polymorphic_oarchive_route@V?$xml_o archive_impl@Vxml_oarchive@archive@boost@@@archive@boost@@@detail@archiv e@boost@@@detail@archive@boost@@SA_NPBVbasic_serializer@234@@Z) referenced in function "public: __thiscall boost::archive::detail::pointer_oserializer
::pointer_oserializer (void)" (??0?$pointer_oserializer@V?$polymorphic_oarchive_route@V?$xml_oarchive_ impl@Vxml_oarchive@archive@boost@@@archive@boost@@@detail@archive@boost@ @VBase@@@detail@archive@boost@@QAE@XZ) 1>Base.obj : error LNK2019: unresolved external symbol "public: static void __cdecl boost::archive::detail::archive_serializer_map ::erase(class boost::archive::detail::basic_serializer const *)" (?erase@?$archive_serializer_map@V?$polymorphic_oarchive_route@V?$xml_oa rchive_impl@Vxml_oarchive@archive@boost@@@archive@boost@@@detail@archive @boost@@@detail@archive@boost@@SAXPBVbasic_serializer@234@@Z) referenced in function "public: __thiscall boost::archive::detail::pointer_oserializer ::~pointer_oserializer (void)" (??1?$pointer_oserializer@V?$polymorphic_oarchive_route@V?$xml_oarchive_ impl@Vxml_oarchive@archive@boost@@@archive@boost@@@detail@archive@boost@ @VBase@@@detail@archive@boost@@QAE@XZ)
B) I do not see a dll_polymorphic_derived2 test in 1.44 (which is what I'm using) or trunk. I do see a polymorphic_derived2.cpp but I don't see anything obviously wrong with what that has vs what my file has. Note that I'm definitely getting into guid_initializer<Derived>::export_guid() in the DLL. Can I attach files to the list? I have a vs2008 project that I can post. Thanks. Jeremy -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Robert Ramey Sent: Tuesday, January 04, 2011 1:29 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] [serialization] polymorphic archives in dllsandpointer to derived problems Kolb, Jeremy wrote:
I'm having a lot of trouble getting serialization of derived classes through a base pointer working across dlls.
Take a look at dll_polymorphic_derived2 in the serialization test directory. The suggested changes are as follows: I have the following:
DLL (data_types.dll) code:
// delete global includes
stdafx.h: #pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files: #include
// base doesn't have to be exported
Base.h: #pragma once class __declspec(dllexport) Base { friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int version);
public: Base() {} virtual ~Base() {} int i; };
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Base); // Doesn't make a difference.
// base serialization needs to be instantiated for all archives to be used
Base.cpp: #include "stdafx.h" #include "Base.h"
template<class Archive> void Base::serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(i); }
// instantiate for the "real" archives used - that is polymorphic_text_iarchive, etc. // note that I don't believe that this should be necessary for abstract base class Base. // So first try totally excluding this.
template void __declspec(dllexport) Base::serialize(boost::archive::polymorphic_xml_iarchive& ar, const unsigned int version); template void __declspec(dllexport) Base::serialize(boost::archive::polymorphic_xml_oarchive& ar, const unsigned int version);
// be sure to include any other archives which might be used (text, binary, etc) // Derived classes MUST be exported.
Derived.h: #include "Base.h"
class __declspec(dllexport) Derived : public Base { friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int version);
public: Derived() {} Derived(int num) : j(num) {} int j; };
BOOST_CLASS_EXPORT_KEY(Derived);
Derived.cpp: #include "stdafx.h" #include "Derived.h"
template<class Archive> void Derived::serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base); ar & BOOST_SERIALIZATION_NVP(j); }
BOOST_CLASS_EXPORT_IMPLEMENT(Derived);
// instantiate for the "real" archives used - that is polymorphic_xml_iarchive, etc.
template void __declspec(dllexport) Derived::serialize(boost::archive::polymorphic_xml_iarchive& ar, const unsigned int version); template void __declspec(dllexport) Derived::serialize(boost::archive::polymorphic_xml_oarchive& ar, const unsigned int version);
My exe links against the DLL and contains the following:
// should run
#include "stdafx.h" #include "boost/archive/polymorphic_xml_iarchive.hpp" #include "boost/archive/polymorphic_xml_oarchive.hpp"
#include "data_types/Derived.h" #include <fstream>
int _tmain(int argc, _TCHAR* argv[]) { std::ofstream f("c:\\test.xml"); boost::archive::polymorphic_xml_oarchive xml(f);
Base* b = new Derived(123); xml & BOOST_SERIALIZATION_NVP(b);
delete b;
return 0; }
Robert Ramey _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users