views:

69

answers:

3

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

A: 

You need to link to Boost.Serialization library. See the Boost's getting started page.

usta
A: 

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!

Daniel Lidström
Thanks for the quick replies, I'm still having some trouble, but I think I'm at least heading on the right track. I forgot to mention in the original post that I am using the Eclipse CDT for development. I think that you were both right in that it was a linker problem, so after searching a little more, I found an article about setting up boost in eclipse where I had to add boost_serialization under the linker settings' library field. After doing this, I still get the same errors. Any more advice on how I can set up boost with Eclipse? Thanks
Try to see what commandline parameters Ecplips is passing to g++. Then make sure the linking part is correct (you can try running the command outside of Ecplipse). Post it here if you don't get forward.
Daniel Lidström
I'm still having problems, here is the linking command that Eclipse is using: "g++ -o"Testbench" ./demo.o -lboost_serialization" I get the same error from the command line outside of Eclipse. Thanks for your help so far
Is g++ finding the library? If not, then you need to add the directory to libboost_serialization.a. Something like this: g++ -o Testbench demo.o -lboost_serialization -L/usr/lib
Daniel Lidström
A: 

Thank you everyone for all your help. I finally got my problem solved, though my solution is fairly anti-climactic, and probably not that informative.

I had tried to install the boost libraries manually, by downloading them from boost's website directly, and found that all the libraries had been installed in /usr/local/lib, and /usr/local/include/boost/ . After repeatedly running into my original errors, I decided to see if the Synaptic Package Manager could do a 'better' job of installing the boost libraries. I selected 'libboost1.40-all-dev' to install everything, but still nothing was working.

Finally, I decided to start fresh so manually deleted the boost/ directory in /usr/local/include, and I deleted all the libboost files in /usr/local/lib. I then marked all the boost libraries for complete removal to remove everything. Once all the boost libraries were uninstalled, I went back to the Synaptic Package Manager, selected 'libboost1.40-all-dev' one more time.

I am not sure what exactly changed when I re-installed the libraries again, but everything started to work again. I first tested from the command line, and tried to compile the demo.cpp from boost's website one more time with the following command:

g++ demo.cpp -lboost_serialization

and it compiled immediately. Running the executable displayed exactly the results I was looking for. Furthermore, I moved the file back into my Eclipse project, added 'boost_serialization' to the Linker libraries, and tried to build the project. Everything worked perfectly again, as I could build the project and run the example code.

I don't really have an explanation for why this fixed my problem, but to anyone else experiencing similar problems, the best advice I can give is to NOT install the boost libraries directly, but rather have the Synaptic Package Manager handle everything.

Thanks again everyone, you've been extremely helpful.