Boost Users :
Subject: Re: [Boost-users] [Serialization] Linker error on BOOST_CLASS_EXPORTupgrading from 1.44.0
From: Robert Ramey (ramey_at_[hidden])
Date: 2011-07-29 12:35:41
Enrico Carrara wrote:
> On Mon, Jul 25, 2011 at 6:30 PM, Robert Ramey <ramey_at_[hidden]> wrote:
> Look at the most recent documentation. BOOST_CLASS_EXPORT is now
> with two different macros (BOOST_CLASS_EXPORT_DECLARE and DEFINE or
> something like that) This permits one to arrange his code so that
> multiple definitions are avoided.
> Thank you very much for your answer.
> I tried using the two new macros (BOOST_CLASS_EXPORT_KEY and
> BOOST_CLASS_EXPORT_IMPLEMENT). I replaced all the previous
> BOOST_CLASS_EXPORT in SerClassExport.h with the corresponding _KEY,
> and this solved the linker problem. So far, so good.
> Then, in order to provided explicit code instantiation, I created a
> new translation unit, "SerClassExport.cpp", as follows:
> // SerClassExport.cpp
> #include <boost/archive/text_iarchive.hpp>
> #include <boost/archive/text_oarchive.hpp>
> #include <boost/archive/xml_iarchive.hpp>
> #include <boost/archive/xml_oarchive.hpp>
> #include "Model_Root.h"
> #include "SM/SM_Node.h"
> [...Many other class definition headers includes]
> #include <boost/serialization/export.hpp>
> [...Many other class export definitions]
> I did it this way because, as far as I understand, I must include all
> the archives before the _IMPLEMENT macros.
> Now, when compiling SerClassExport.cpp, the compiler again goes out
> of heap space, as it did before splitting the original unique .cpp
> into two translation units - one for each archive type.
> Am I doing it right? It seems that I did not catch how to have two
> separate translation units without redefinition of
> Of course, if I remove the "extra_detail" namespace in export.hpp
> (coming back to an unnamed namespace as it was in 1.44.0), everything
> goes ok, but I can hardly think that this might be a feasible
> Any idea on possible alternatives?
> Thank you in advance,
I'm going to guess that there's too much instatiation going on. Try the
a) try changing the headers so they don't inlcude inline functions. Put
definitions in a separate cpp or ipp file.
b) since a is a huge amount of work. Try this: build your above
module a little at a time. That is - comment out most of the headers
and try to build - of course it will fail to link. Add headers until
it starts to have the problem. The basic goal is to find which
templates are being "accdently instantiated multiple times.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net