|
Boost Users : |
Subject: Re: [Boost-users] Serialize a vector of lists with boost
From: François Mauger (mauger_at_[hidden])
Date: 2011-06-15 11:25:49
On 15/06/2011 09:53, Alessandro Candini wrote:
> Thank you so much for your example!
>
> I would like to study it, but I cannot compile it actually.
>
Not exactly, it almost compiles but sure does not link !
You must use a linker path option in your build command, otherwize there
is no way the compiler/linker can find the proper files
if you don't use a Boost installation in some standard /usr location:
> I'm using gcc-4.5.2 on an Ubuntu Linux 64 bits with boost-1.42.0.
>
> At line 127 (boost::archive::text_oarchive toa (toafile);), it gives me
> the following error:
> g++ -Wall -pedantic -g -O3 -DDEBUG -march=native -std=c++0x -o p1 p1.cxx
Typically, before compiling, a nice thing to setup in your *nix
environment is (here for a sh-flavor shell):
# the Boost include path :
export BOOST_CFLAGS=-I<path_to_the_boost_include_base_directory>
# the Boost lib path :
export BOOST_LDFLAGS=-L<path_to_the_boost_libs_base_directory> \
-lserialization
# Also add the DLL path for runtime DLL resolution :
export LD_LIBRARY_PATH=\
<path_to_the_boost_libs_base_directory>:${LD_LIBRARY_PATH}
# Build it :
g++ -Wall -pedantic -g -O3 -DDEBUG -march=native -std=c++0x \
${BOOST_CFLAGS}-o p1 p1.cxx ${BOOST_LDFLAGS}
# Run :
./p1
> /tmp/cc5wHYcd.o: In function `text_oarchive':
> /usr/include/boost/archive/text_oarchive.hpp:92: undefined reference to
> `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::basic_ostream<char,
> std::char_traits<char> >&, unsigned int)'
> /tmp/cc5wHYcd.o: In function `~common_oarchive':
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /tmp/cc5wHYcd.o: In function `~text_oarchive_impl':
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /tmp/cc5wHYcd.o: In function `~text_oarchive':
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /tmp/cc5wHYcd.o: In function
> `save_primitive<boost::archive::text_oarchive, int>':
> /usr/include/boost/archive/detail/oserializer.hpp:87: undefined
> reference to `boost::archive::detail::basic_oarchive::end_preamble()'
> /tmp/cc5wHYcd.o: In function `save<int>':
> /usr/include/boost/archive/text_oarchive.hpp:59: undefined reference to
> `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
> /tmp/cc5wHYcd.o: In function `save<int>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to
> `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code,
> char const*, char const*)'
> /tmp/cc5wHYcd.o: In function `archive_exception':
> /usr/include/boost/archive/archive_exception.hpp:45: undefined reference
> to `vtable for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function
> `throw_exception<boost::archive::archive_exception>':
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `typeinfo for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function `operator<< <const
> boost::archive::class_id_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /tmp/cc5wHYcd.o: In function `~common_oarchive':
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /tmp/cc5wHYcd.o: In function `~text_oarchive_impl':
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /tmp/cc5wHYcd.o: In function `~common_oarchive':
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /tmp/cc5wHYcd.o: In function
> `save_primitive<boost::archive::text_oarchive, std::basic_string<char> >':
> /usr/include/boost/archive/detail/oserializer.hpp:87: undefined
> reference to `boost::archive::detail::basic_oarchive::end_preamble()'
> /usr/include/boost/archive/detail/oserializer.hpp:88: undefined
> reference to
> `boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > const&)'
> /tmp/cc5wHYcd.o: In function `~common_oarchive':
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /tmp/cc5wHYcd.o: In function `~text_oarchive_impl':
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /tmp/cc5wHYcd.o: In function `~common_oarchive':
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /tmp/cc5wHYcd.o: In function `~text_oarchive_impl':
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /tmp/cc5wHYcd.o: In function `~common_oarchive':
> /usr/include/boost/archive/detail/common_oarchive.hpp:38: undefined
> reference to `boost::archive::detail::basic_oarchive::~basic_oarchive()'
> /tmp/cc5wHYcd.o: In function `~text_oarchive_impl':
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /usr/include/boost/archive/text_oarchive.hpp:77: undefined reference to
> `boost::archive::basic_text_oprimitive<std::basic_ostream<char,
> std::char_traits<char> > >::~basic_text_oprimitive()'
> /tmp/cc5wHYcd.o: In function
> `save_primitive<boost::archive::text_oarchive,
> boost::archive::tracking_type>':
> /usr/include/boost/archive/detail/oserializer.hpp:87: undefined
> reference to `boost::archive::detail::basic_oarchive::end_preamble()'
> /tmp/cc5wHYcd.o: In function `save<boost::archive::tracking_type>':
> /usr/include/boost/archive/text_oarchive.hpp:59: undefined reference to
> `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
> /tmp/cc5wHYcd.o: In function `save<boost::archive::tracking_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to
> `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code,
> char const*, char const*)'
> /tmp/cc5wHYcd.o: In function `archive_exception':
> /usr/include/boost/archive/archive_exception.hpp:45: undefined reference
> to `vtable for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function
> `throw_exception<boost::archive::archive_exception>':
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `typeinfo for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function `operator<< <const
> boost::archive::tracking_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /tmp/cc5wHYcd.o: In function `save<unsigned int>':
> /usr/include/boost/archive/text_oarchive.hpp:59: undefined reference to
> `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
> /tmp/cc5wHYcd.o: In function `save<unsigned int>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to
> `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code,
> char const*, char const*)'
> /tmp/cc5wHYcd.o: In function `archive_exception':
> /usr/include/boost/archive/archive_exception.hpp:45: undefined reference
> to `vtable for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function
> `throw_exception<boost::archive::archive_exception>':
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `typeinfo for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function `operator<< <const
> boost::archive::object_id_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /tmp/cc5wHYcd.o: In function
> `save_primitive<boost::archive::text_oarchive, int>':
> /usr/include/boost/archive/detail/oserializer.hpp:87: undefined
> reference to `boost::archive::detail::basic_oarchive::end_preamble()'
> /tmp/cc5wHYcd.o: In function `save<int>':
> /usr/include/boost/archive/text_oarchive.hpp:59: undefined reference to
> `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
> /tmp/cc5wHYcd.o: In function `save<int>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to
> `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code,
> char const*, char const*)'
> /tmp/cc5wHYcd.o: In function `archive_exception':
> /usr/include/boost/archive/archive_exception.hpp:45: undefined reference
> to `vtable for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function
> `throw_exception<boost::archive::archive_exception>':
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `typeinfo for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function `operator<< <const
> boost::archive::class_id_reference_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /tmp/cc5wHYcd.o: In function
> `save_primitive<boost::archive::text_oarchive, unsigned int>':
> /usr/include/boost/archive/detail/oserializer.hpp:87: undefined
> reference to `boost::archive::detail::basic_oarchive::end_preamble()'
> /tmp/cc5wHYcd.o: In function `save<unsigned int>':
> /usr/include/boost/archive/text_oarchive.hpp:59: undefined reference to
> `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
> /tmp/cc5wHYcd.o: In function `save<unsigned int>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to
> `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code,
> char const*, char const*)'
> /tmp/cc5wHYcd.o: In function `archive_exception':
> /usr/include/boost/archive/archive_exception.hpp:45: undefined reference
> to `vtable for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function
> `throw_exception<boost::archive::archive_exception>':
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `typeinfo for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function `operator<< <const
> boost::archive::version_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /tmp/cc5wHYcd.o: In function `save<unsigned int>':
> /usr/include/boost/archive/text_oarchive.hpp:59: undefined reference to
> `boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
> /tmp/cc5wHYcd.o: In function `save<unsigned int>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to
> `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception::exception_code,
> char const*, char const*)'
> /tmp/cc5wHYcd.o: In function `archive_exception':
> /usr/include/boost/archive/archive_exception.hpp:45: undefined reference
> to `vtable for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function
> `throw_exception<boost::archive::archive_exception>':
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /usr/include/boost/serialization/throw_exception.hpp:36: undefined
> reference to `typeinfo for boost::archive::archive_exception'
> /tmp/cc5wHYcd.o: In function `operator<< <const
> boost::archive::object_reference_type>':
> /usr/include/boost/archive/basic_text_oprimitive.hpp:88: undefined
> reference to `boost::archive::archive_exception::~archive_exception()'
> /tmp/cc5wHYcd.o:(.rodata._ZTIN5boost7archive6detail15common_oarchiveINS0_13text_oarchiveEEE[typeinfo
> for
> boost::archive::detail::common_oarchive<boost::archive::text_oarchive>]+0x18):
> undefined reference to `typeinfo for boost::archive::detail::basic_oarchive'
> collect2: ld returned 1 exit status
> make: *** [boostSerialization] Error 1
>
> Have I a too old version of the libraries maybe?
>
>> Hi Alessandro,
>>
>> Attached is a sample program that illustrates how to (de)serialize
>> your vector of lists of pointers to something !!!
>> It should address your needs to start with Boost/Serialization.
>> It runs on my Linux box with gcc 4.5. I hope it will work for you.
>>
>> Also note that the use of plain pointers (MyObj *) in a container can
>> be tricky unless you can make sure you run suitable memory
>> deallocation code. Of course, it depends on your application but maybe
>> investigating the used of shared pointer (boost::shared_ptr) could be
>> of some interest
>> for you.
>>
>> Hope it'd help
>>
>> regards
>>
>> frc
>> --
>>
>>
>> >>> On 14/06/2011 10:02, Alessandro Candini wrote:
>>> Hi all.
>>> I have a program, simplified as follows:
>>>
>>> |#include<vector>
>>> #include<list>
>>> #include<fstream>
>>>
>>> using namespace std;
>>>
>>> class MyObj
>>> {
>>> int val;
>>>
>>> public:
>>> MyObj(int v){ val = v; };
>>> ~MyObj(){};
>>> };
>>>
>>> int main (int argc,char *argv[])
>>> {
>>> int i, j;
>>> vector< list<MyObj*> > layers;
>>>
>>> for(i=0; i<5; i++)
>>> {
>>> list<MyObj*> tmp;
>>>
>>> for(j=0; j<10; j++)
>>> tmp.push_back(new MyObj(j) );
>>>
>>> layers.push_back(tmp);
>>> }
>>> return 0;
>>> }|
>>>
>>> I need to serialize/deserialize the object "layers".
>>>
>>> Can anyone give me an example on how to do this with boost serialization
>>> library?
>>>
>>> Thanks in advance.
>>>
>>> --
>>> Alessandro Candini
>>>
>>> MEEO S.r.l.
>>> Via Saragat 9
>>> I-44122 Ferrara, Italy
>>> Tel: +39 0532 1861501
>>> Fax: +39 0532 1861637
>>> http://www.meeo.it
>>>
>>> ========================================
>>> "ATTENZIONE:le informazioni contenute in questo messaggio sono
>>> da considerarsi confidenziali ed il loro utilizzoè riservato unicamente
>>> al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
>>> per erroreè tenuto ad informare il mittente ed a rimuoverlo
>>> definitivamente da ogni supporto elettronico o cartaceo."
>>>
>>> "WARNING:This message contains confidential and/or proprietary
>>> information which may be subject to privilege or immunity and which
>>> is intended for use of its addressee only. Should you receive this
>>> message in error, you are kindly requested to inform the sender and
>>> to definitively remove it from any paper or electronic format."
>>>
>>>
>>>
>>> _______________________________________________
>>> Boost-users mailing list
>>> Boost-users_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>>
>>
>>
>> _______________________________________________
>> Boost-users mailing list
>> Boost-users_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> --
> Alessandro Candini
>
> MEEO S.r.l.
> Via Saragat 9
> I-44122 Ferrara, Italy
> Tel: +39 0532 1861501
> Fax: +39 0532 1861637
> http://www.meeo.it
>
> ========================================
> "ATTENZIONE:le informazioni contenute in questo messaggio sono
> da considerarsi confidenziali ed il loro utilizzoè riservato unicamente
> al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
> per erroreè tenuto ad informare il mittente ed a rimuoverlo
> definitivamente da ogni supporto elettronico o cartaceo."
>
> "WARNING:This message contains confidential and/or proprietary
> information which may be subject to privilege or immunity and which
> is intended for use of its addressee only. Should you receive this
> message in error, you are kindly requested to inform the sender and
> to definitively remove it from any paper or electronic format."
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- François Mauger Groupe "Interactions Fondamentales et Nature du Neutrino" NEMO-3/SuperNEMO Collaboration LPC Caen-CNRS/IN2P3-UCBN-ENSICAEN Département de Physique -- Université de Caen Basse-Normandie Adresse/address: Laboratoire de Physique Corpusculaire de Caen (UMR 6534) ENSICAEN 6, Boulevard du Marechal Juin 14050 CAEN Cedex FRANCE Courriel/e-mail: mauger_at_[hidden] Tél./phone: 02 31 45 25 12 / (+33) 2 31 45 25 12 Fax: 02 31 45 25 49 / (+33) 2 31 45 25 49
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