Boost logo

Boost Users :

Subject: Re: [Boost-users] undefined reference to base_object
From: John C (johnc_at_[hidden])
Date: 2010-05-02 11:51:27


Robert,

Thanks for the quick response. This may be part of my confusion, and since
visual studio is so screwy with how it lets certain things go that often
won't even compile with gcc. Anyway, I have a shared library that doesn't
use the serialization portion of the code, and can't have boost as a
dependency, so we have a forward declaration that allows compilation.

Header file:

forward declaration:
namespace boost { namespace serialization { class access; template<class
Base, class Derived> Base& base_object(const Derived &d); } }

In the private portion of the derived class declaration I have basically the
following:

friend class boost::serialization::access;
template<class Archive>
        void serialize(Archive & ar, const unsigned int version)
        {
            ar & boost::serialization::base_object<MyBaseClass,
MyDerivedClass>(*this);
            ar & mMember;
        }

The base class is similar, minus of course the base_object call.

The real library that uses the serialization code is in a static library
that is included by a couple other shared libraries. When I upgraded to
VS2008 (and boost 1.40.0) last year, I had some problems (in Windows) with
unregistered classes. I found information (in the link in my post) that led
me to move my export macros to a source file. I ended up also having to
include the source file in each of the dependent shared libraries to get it
to work. I never really did fully understand why that made it work, but I
assumed it had something to do with the code being in a static library.

Fast forward to now (linux), I have tried including that source file
directly (and through the static library) in an executable that is a test
runner to verify the serialization code is working, and this is where I am
stuck.

Hopefully that gives you enough information to better understand my problem.
I appreciate you taking the time to answer my question.

Robert Ramey wrote:
>
> John C wrote:
>> I am working with the boost 1.40.0 serialization library and I am
>> having trouble with class registration for polymorphic types. The
>> code I have has worked fine with VS2005 and VS2008 for a long time;
>> however, in linux with gcc (4.4.1-4ubuntu9), I am having issues.
>>
>> I am using the non-intrusive serialization method on a class that
>> resides in a shared object file. I have simplified this down to where
>> the serialization of the object is performed in an executable linking
>> in the shared object file. In Windows I am registering the classes
>> with boost using BOOST_CLASS_EXPORT_GUID. However, in linux, if I
>> register the classes using this macro, the code compiles but does not
>> link and gives an error similar to below for :
>>
>>
>> testConfig.o: In function
>> `boost::archive::detail::iserializer<boost::archive::text_iarchive,
>> MyNamespace::MyDerivedClass>::load_object_data(boost::archive::detail::basic_iarchive&,
>> void*, unsigned int) const':
>> testConfig.cpp:(.text._ZNK5boost7archive6detail11iserializerINS0_13text_iarchiveEN7MoreOfMyClassRelatredDataEE16load_object_dataERNS1_14basic_iarchiveEPvj[boost::archive::detail::iserializer<boost::archive::text_iarchive,
>> MyNamespace::MyDerivedClass>::load_object_data(boost::archive::detail::basic_iarchive&,
>> void*, unsigned int) const]+0x96): undefined reference to
>> `MyNamespace::MyBaseClass&
>> boost::serialization::base_object<MyNamespace::MyBaseClass,
>> MyNamespace::MyDerivedClass>(MyNamespace::MyDerivedClass const&)'
>>
>> The same error also occurs with save_object_data.
>
> without seeing more, the only thing that occurs to me is to check that
> your non-instrusive save/load functions are in the correct namespace.
>
> Robert Ramey
>
>>
>>
>> If I don't register, my test fails with the unregistered class
>> exception. I have tried placing the macros in both a header and a
>> source file and I still get the linker errors following advice from
>> here:
>> http://www.boost.org/doc/libs/1_40_0/libs/serialization/doc/special.html#export.
>> I also tried explicitly instantiating the base_object methods, but
>> get an error indicating no matching definition exists, so I am
>> assuming this is related to the issue - I'm just not sure how else to
>> define the function. I am familiar with basic templating, but the
>> serialization library source is beyond me.
>>
>> Any help would be greatly appreciated.....
>>
>> Thanks - John
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>

-- 
View this message in context: http://old.nabble.com/undefined-reference-to-base_object-tp28417529p28427706.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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