Hello,
I am facing a problem with serialization as implemented in Boost 1.47.0
which I did not experience in version 1.44.0.
The problem appears as a series of linker errors (Visual C++ 8.0 (VS2005),
WinXP 32bit):
1>Compiling...
1>Model_SerializationXml.cpp
1>Model_SerializationTxt.cpp
1>Compiling manifest to resources...
1>Linking...
1>Model_SerializationXml.obj : error LNK2005: "public: static struct
boost::archive::detail::extra_detail::guid_initializer<class
sm::CompLoad_Test> const & const
boost::archive::detail::extra_detail::init_guid<class sm::CompLoad_Test>::g"
(?g@?$init_guid@VCompLoad_Test@sm@@@extra_detail@detail@archive@boost
@@2ABU?$guid_initializer@VCompLoad_Test@sm@@@2345@B) already defined in
Model_SerializationTxt.obj
[...many more similar errors]
The scenario is as follows:
I have a considerable bunch of classes which must be serialized by means of
both text and XML archives.
To this purpose, I have two compilation units, "Model_SerializationTxt.cpp"
and "Model_SerializationXml.cpp", as follows:
/////////////////////////////////////////////////
// Model_SerializationTxt.cpp
[...]
#include
#include
#include
[...]
#include "SerClassExport.h"
[...]
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// Model_SerializationXml.cpp
[...]
#include
#include
#include
[...]
#include "SerClassExport.h"
[...]
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// SerClassExport.h
[...]
// APPLICATION_DEPENDENT: Include here files
// relevant to model classes to be exported
// for serialization
#include "Model_Root.h"
#include "SM/SM_Node.h"
[...Many more class definition headers]
[...]
#include
// APPLICATION_DEPENDENT: Include here files
// relevant to model classes to be exported
// for serialization
BOOST_CLASS_EXPORT(model::Root)
BOOST_CLASS_EXPORT(sm::Node)
[...Many more class export definitions]
[...]
/////////////////////////////////////////////////
The problem seems to be related to the fact that BOOST_CLASS_EXPORT is
defined twice in my project.
In Boost 1.44.0, struct guid_initializer was defined in "export.hpp" inside
an anonymous namespace, while in Boost 1.47.0 - actually, since version
1.45.0 - the definition is inside namespace extra_detail, even if the
comment above is unchanged:
/////////////////////////////////////////////////
// export.hpp in Boost 1.44.0
[...]
// Note INTENTIONAL usage of anonymous namespace in header.
// This was made this way so that export.hpp could be included
// in other headers. This is still under study.
namespace {
template<class T>
struct guid_initializer
[...]
#define BOOST_CLASS_EXPORT_IMPLEMENT(T)\
namespace boost {\
namespace archive {\
namespace detail {\
namespace {\
template<>\
struct init_guid< T > {\
static guid_initializer< T > const & g;\
};\
guid_initializer< T > const & init_guid< T >::g =\
::boost::serialization::singleton<\
guid_initializer< T >\
>::get_mutable_instance().export_guid();\
}}}}\
[...]
/////////////////////////////////////////////////
/////////////////////////////////////////////////
// export.hpp in Boost 1.47.0
[...]
// Note INTENTIONAL usage of anonymous namespace in header.
// This was made this way so that export.hpp could be included
// in other headers. This is still under study.
namespace extra_detail {
template<class T>
struct guid_initializer
[...]
#define BOOST_CLASS_EXPORT_IMPLEMENT(T)\
namespace boost {\
namespace archive {\
namespace detail {\
namespace extra_detail {\
template<>\
struct init_guid< T > {\
static guid_initializer< T > const & g;\
};\
guid_initializer< T > const & init_guid< T >::g =\
::boost::serialization::singleton<\
guid_initializer< T >\
>::get_mutable_instance().export_guid();\
}}}}\
[...]
/////////////////////////////////////////////////
I guess that this might have a role in originating the linker problem.
How can I avoid this error? I already tried including the list of
BOOST_CLASS_EXPORT only once, i.e in Model_SerializationTxt.cpp only. This
solved the linker problem, but serialization of data in XML was then
impossible (runtime error).
Unfortunately, merging the two compilation units in one is not possible,
because the compiler (Visual C++ 8.0) goes out of memory while compiling the
big unit (process memory grows beyond 2GB).
Is there, in your opinion, a solution or a workaround to this situation?
Let me apologize for the very long mail, I did not succeed in shortening it
further.
Looking forward to any possible advice,
thank you in advance for your attention.
Enrico