Help compiling and using boost c++ libraries

Swaraj picture Swaraj · Oct 14, 2010 · Viewed 11.7k times · Source

I am working on a C++ project where I'd like to use boost's serialization libraries. I downloaded and installed the latest boost libraries from boost's home page.

When I tried to compile and run the one of boost's demo serialization examples, I got all sorts of errors that looked like this:

    /usr/local/include/boost/archive/detail/iserializer.hpp:173: undefined reference to `boost::archive::archive_exception::~archive_exception()'
./demo.o: In function `void boost::archive::detail::save_non_pointer_type<boost::archive::text_oarchive>::save_standard::invoke<bus_schedule::trip_info>(boost::archive::text_oarchive&, bus_schedule::trip_info const&)':
/usr/local/include/boost/archive/detail/oserializer.hpp:253: undefined reference to `boost::archive::detail::basic_oarchive::save_object(void const*, boost::archive::detail::basic_oserializer const&)'
./demo.o: In function `void boost::archive::save_access::end_preamble<boost::archive::text_oarchive>(boost::archive::text_oarchive&)':
/usr/local/include/boost/archive/detail/oserializer.hpp:83: undefined reference to `boost::archive::detail::basic_oarchive::end_preamble()'
./demo.o: In function `void boost::archive::detail::load_pointer_type<boost::archive::text_iarchive>::invoke<bus_route*>(boost::archive::text_iarchive&, bus_route*&)':
/usr/local/include/boost/archive/detail/iserializer.hpp:518: undefined reference to `boost::archive::detail::basic_iarchive::load_pointer(void*&, boost::archive::detail::basic_pointer_iserializer const*, boost::archive::detail::basic_pointer_iserializer const* (*)(boost::serialization::extended_type_info const&))'
./demo.o: In function `void boost::archive::detail::save_pointer_type<boost::archive::text_oarchive>::non_polymorphic::save<bus_route>(boost::archive::text_oarchive&, bus_route&)':

I am new to C++ and boost so any help would be appreciated.

Thanks

Answer

Daniel Lidstr&#246;m picture Daniel Lidström · Oct 14, 2010

Presumably you need to link to the serialization library. Have a look in /usr/lib for something with a name similar to libboost_serialization. Then tell g++ (you didn't say which compiler you are using) you want to use (link to) this library:

g++ main.cpp -lboost_serialization

I.e. if the name of the library is /usr/lib/libboost_serialization.a you leave out the initial lib and the extension.

Good luck!