|
Boost : |
From: troy d. straszheim (troy_at_[hidden])
Date: 2005-03-13 03:15:02
#if defined(BOOST_ARCHIVE_BINARY_WOARCHIVE_HPP)
#if ! defined(BOOST_ARCHIVE_EXPORT)
#define BOOST_ARCHIVE_EXPORT
#endif
, boost::archive::binary_woarchive
#endif
---> #if ! defined(BOOST_ARCHIVE_EXPORT)
---> #define BOOST_ARCHIVE_EXPORT
---> #endif
#if defined(BOOST_ARCHIVE_BINARY_WIARCHIVE_HPP)
#if ! defined(BOOST_ARCHIVE_EXPORT)
#define BOOST_ARCHIVE_EXPORT
#endif
, boost::archive::binary_wiarchive
#endif
You can't BOOST_EXPORT_CLASS() without including an archive type
first... the snippet above, from known_archive_types.hpp, breaks things
if you include serialization/export.hpp and BOOST_EXPORT_CLASS() in a
header file without including an archive header: BOOST_ARCHIVE_EXPORT
gets #defined even if you haven't previously included an archive header,
and then some of the metaprogramming stuff involving managing lists of
known archives gets pulled in, but with empty mpl lists, compile error
ensues. So what naturally happens is you include the archive header
above the export header, to stop the compile problem, and then you get
bitten later by the multiple-symbol thing at link time.
Here's a test that shows the bug:
#include <boost/serialization/export.hpp>
struct S { };
BOOST_CLASS_EXPORT(S)
// EOF
Robert, I sent you this off-list, apologies for the noise, if I'm
missing some subtlety and am off-base...
troy d. straszheim
Robert Ramey wrote:
> Are you sure this worked before? That would surprise me.
>
> The problem is that template that implement the "export" functionality are
> instantiated for each archive type previously "seen" in the header. So
> including the following
>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/serialization/export.hpp>
>
> BOOST_CLASS_EXPORT(C)
>
> in multiple modules is going to produce multiple symbols at link time.
>
> My suggestion would be to include the archive headers only in the modules
> that actually invoke serialization. And that be only in one module. My
> intention was that each class header contain BOOST_CLASS_EXPORT for its
> classes and the the "main" or other module (see demo_pimpl) that actually
> invoked the serialization would include the headers for the archive classes
> that are desired. This makes it easy to switch between archive types for
> things like debugging, etc.
>
> Robert Ramey
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk