I have recently ran into an error when compiling my program with the boost serialization library.
I have read across many forums that I need to link the boost serialization library (-lboost_serialization). Which, I did.
However, there is one error that I am getting on the code:
/usr/local/boost_1_64_0/boost/serialization/throw_exception.hpp:36: undefined reference to `boost::archive::archive_exception::archive_exception(boost::archive::archive_exception const&)' So I thought, what if I have to also include the exception library? So I added this into the libraries for my compiler settings:
-lboost_exception However, now it is saying that it is unable to find the boost_exception library. Which is interesting because I am able to see it in the file system!
I am wondering if I am doing the right thing or am I forgetting to add something to my compiler settings? Any help will be much appreciated!
Edit:
Here is the code:
// MS compatible compilers support #pragma once #if defined(_MSC_VER) # pragma once #endif // boost/throw_exception.hpp // // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include <boost/config.hpp> #ifndef BOOST_NO_EXCEPTIONS #include <exception> #endif namespace boost { namespace serialization { #ifdef BOOST_NO_EXCEPTIONS inline void throw_exception(std::exception const & e) { ::boost::throw_exception(e); } #else template<class E> inline void throw_exception(E const & e){ throw e;// Error occurs here } #endif } // namespace serialization } // namespace boost Here is a code sample where the breakage occurs
#include <boost/archive/text_oarchive.hpp> #include <boost/archive/text_iarchive.hpp> #include <vector> #include "boost/serialization/vector.hpp" #include <string> #include <fstream> int main() { std::ofstream ofs("/home/phillip/test.txt"); std::vector<std::string> tests; boost::archive::text_oarchive oa(ofs); oa << tests; }