Boost logo

Boost :

Subject: [boost] compile error with boost::archive::text_oarchive
From: Eun-Sung Kim (eskimokr_at_[hidden])
Date: 2011-03-17 11:59:00


Hi, all

Compile error is occurred in the following program "VerySimpleCase
.cpp" on http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/tutorial.html#simplecase.
The statements in line no. 45 and 56 cause problems.
Could you fix it up?
Thanks,
--Kim

ps 1) VerySimpleCase .cpp
   1 #include <fstream>
   2
   3 // include headers that implement a archive in simple text format
   4 #include <boost/archive/text_oarchive.hpp>
   5 #include <boost/archive/text_iarchive.hpp>
   6
   7 /////////////////////////////////////////////////////////////
   8 // gps coordinate
   9 //
 10 // illustrates serialization for a simple type
 11 //
 12 class gps_position
 13 {
 14 private:
 15 friend class boost::serialization::access;
 16 // When the class Archive corresponds to an output archive, the
 17 // & operator is defined similar to <<. Likewise, when the
class Archive
 18 // is a type of input archive the & operator is defined similar to >>.
 19 template<class Archive>
 20 void serialize(Archive & ar, const unsigned int version)
 21 {
 22 ar & degrees;
 23 ar & minutes;
 24 ar & seconds;
 25 }
 26 int degrees;
 27 int minutes;
 28 float seconds;
 29 public:
 30 gps_position(){};
 31 gps_position(int d, int m, float s) :
 32 degrees(d), minutes(m), seconds(s)
 33 {}
 34 };
 35
 36 int main() {
 37 // create and open a character archive for output
 38 std::ofstream ofs("filename");
 39
 40 // create class instance
 41 const gps_position g(35, 59, 24.567f);
 42
 43 // save data to archive
 44 {
 45 boost::archive::text_oarchive oa(ofs); // compile error
at here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 46 // write class instance to archive
 47 oa << g;
 48 // archive and stream closed when destructors are called
 49 }
 50
 51 // ... some time later restore the class instance to its orginal state
 52 gps_position newg;
 53 {
 54 // create and open an archive for input
 55 std::ifstream ifs("filename");
 56 boost::archive::text_iarchive ia(ifs); // compile
error at here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 57 // read class state from archive
 58 ia >> newg;
 59 // archive and stream closed when destructors are called
 60 }
 61 return 0;
 62 }
 63

ps2) compile error message (partly)
/tmp/ccnNHOct.o: In function `boost::archive::text_iarchive&
boost::smart_cast_impl::reference<boost::archive::text_iarchive&>::polymorphic::cross::cast<boost::archive::detail::basic_iarchive>(boost::archive::detail::basic_iarchive&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost15smart_cast_impl9referenceIRNS_7archive13text_iarchiveEE11polymorphic5cross4castINS2_6detail14basic_iarchiveEEES4_RT_+0x1b):
undefined reference to `typeinfo for
boost::archive::detail::basic_iarchive'
/tmp/ccnNHOct.o: In function `boost::archive::text_oarchive&
boost::smart_cast_impl::reference<boost::archive::text_oarchive&>::polymorphic::cross::cast<boost::archive::detail::basic_oarchive>(boost::archive::detail::basic_oarchive&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost15smart_cast_impl9referenceIRNS_7archive13text_oarchiveEE11polymorphic5cross4castINS2_6detail14basic_oarchiveEEES4_RT_+0x1b):
undefined reference to `typeinfo for
boost::archive::detail::basic_oarchive'
/tmp/ccnNHOct.o: In function `void
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<int>(int
const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive18text_oarchive_implINS0_13text_oarchiveEE4saveIiEEvRKT_+0x15):
undefined reference to
`boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
/tmp/ccnNHOct.o: In function `void
boost::archive::save_access::save_primitive<boost::archive::text_oarchive,
int>(boost::archive::text_oarchive&, int const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive11save_access14save_primitiveINS0_13text_oarchiveEiEEvRT_RKT0_+0x15):
undefined reference to
`boost::archive::detail::basic_oarchive::end_preamble()'
/tmp/ccnNHOct.o: In function `void
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type
const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive18text_oarchive_implINS0_13text_oarchiveEE4saveINS0_23class_id_reference_typeEEEvRKT_+0x15):
undefined reference to
`boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
/tmp/ccnNHOct.o: In function `void
boost::archive::save_access::save_primitive<boost::archive::text_oarchive,
boost::archive::class_id_reference_type>(boost::archive::text_oarchive&,
boost::archive::class_id_reference_type const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive11save_access14save_primitiveINS0_13text_oarchiveENS0_23class_id_reference_typeEEEvRT_RKT0_+0x15):
undefined reference to
`boost::archive::detail::basic_oarchive::end_preamble()'
/tmp/ccnNHOct.o: In function `void
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<boost::archive::class_id_type>(boost::archive::class_id_type
const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive18text_oarchive_implINS0_13text_oarchiveEE4saveINS0_13class_id_typeEEEvRKT_+0x15):
undefined reference to
`boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'
/tmp/ccnNHOct.o: In function `void
boost::archive::save_access::save_primitive<boost::archive::text_oarchive,
boost::archive::class_id_type>(boost::archive::text_oarchive&,
boost::archive::class_id_type const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive11save_access14save_primitiveINS0_13text_oarchiveENS0_13class_id_typeEEEvRT_RKT0_+0x15):
undefined reference to
`boost::archive::detail::basic_oarchive::end_preamble()'
/tmp/ccnNHOct.o: In function `void
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save<float>(float
const&)':
VerySimpleCase.cpp:(.gnu.linkonce.t._ZN5boost7archive18text_oarchive_implINS0_13text_oarchiveEE4saveIfEEvRKT_+0x15):
undefined reference to
`boost::archive::basic_text_oarchive<boost::archive::text_oarchive>::newtoken()'


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk