Boost logo

Boost Users :

From: Bill Lear (rael_at_[hidden])
Date: 2005-01-07 08:27:19

I am having some trouble understanding just where I am supposed to
put BOOST_CLASS_EXPORT macros for classes I write --- in class
headers (.h), in class implementation files (.cc), in applications
that plan to save/load through base pointers?

I have base class B, from which I derive lots of classes. I tried
putting the BOOST_CLASS_EXPORT in the header files of each class, but
soon found that this resulted in link-time errors due to multiple

So, I moved the macro to an implementation (.cc) file, creating it if
necessary, with the form:

    #include "Derived.h"


The problem with this is that I have an application that does this:

    #include "Base.h"
    #include "Derived.h" // fails with or without this

    void foo() {
        Base* b = load("file.xml");

Now, since no instance of Derived is appearing in my application,
the linker apparently does not pull in the (expanded) macro, and when
I run the application, I get an unregistered class exception.

So, I removed all of the macros from the implementation files and
put them in a header (again), that is designed for applications that
may want to serialize (any) of my derived classes:

    #include "Base.h"
    #include "Derived.h"
    #include "BoostExports.h"

    void foo() {
        Base* b = load("file.xml");

and this works fine.

So my question is this: is this what other people do, or are there other
solutions that people prefer?

The problem with the above is that if I have 20 derived classes and
put all the macro exports in BoostExports.h, even if my application
may only be interested in a smaller subset, I have to pull in 20
header files each time, and I had hoped to avoid that. This is not a
terrible thing, I just wondered what other approaches there might be.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at