Boost logo

Boost Users :

Subject: [Boost-users] [serialization] Multiply defined symbol: guid_initializer
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2009-04-02 20:20:47


Hi,
I'm currently trying to polymorphically serialize a class without using
RTTI. I'm doing this currently in a file called StaticText.hpp:

#ifndef RS_GUI_WIDGETS_STATICTEXT_HPP
#define RS_GUI_WIDGETS_STATICTEXT_HPP

#include <boost/scoped_ptr.hpp>
#include <boost/serialization/access.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/extended_type_info_no_rtti.hpp>
#include <boost/serialization/export.hpp>

#include <rs/gui/widgets/Widget.hpp>
#include <rs/gui/Text.hpp>

namespace rs
{
    class StaticText : public Widget
    {
    public:
        StaticText( std::string const& text );

        void Update();
        void Render( RenderSystem& renderer, Camera& camera );
        char const* get_key() const;

    private:
        StaticText() {}

        template< class Archive >
        void serialize( Archive& archive, unsigned int version )
        {
            archive & boost::serialization::base_object<Widget>( *this );

            std::string text;
            archive & text;
            m_text.reset( new Text( text ) );
        }

        boost::scoped_ptr<Text> m_text;

        friend class boost::serialization::access;
    };
}

BOOST_CLASS_TYPE_INFO(
    rs::StaticText,
    extended_type_info_no_rtti<rs::StaticText>
    )

BOOST_CLASS_EXPORT( rs::StaticText )

#endif // RS_GUI_WIDGETS_STATICTEXT_HPP

When I compile this into a LIB first, and then link the lib into an EXE, the
linker says this (Visual Studio 2008):
*gui.lib(StaticText.obj) : error LNK2005: "public: static struct
boost::archive::detail::guid_initializer<class rs::StaticText> const & const
boost::archive::detail::init_guid<class rs::StaticText>::guid_initializer"
(?guid_initializer@?$init_guid_at_VStaticText@rs@@@detail_at_archive@boost@
@2ABU?$guid_initializer_at_VStaticText@rs@@@234_at_B) already defined in main.obj*
*
*
If I move the 2 macro calls into the StaticText.cpp file, everything
compiles/links just fine but I end up getting an exception thrown at runtime
that says "unregistered void cast".



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