Is it possible to use Boost serialization as a header only library?

Below is a minimal example to use the great Boost.Serialization library.

To compile the library I need to link with the boost_serialization precompiled library.

$ c++ -std=c++11 example.cpp -o example.x -lboost_serialization ^^^^^^^^^^^^^^^^^^^^^ 

The library is heavily templated an although complicated internally the actual code (function body) is quite simple. There are only a few references that need the linking, namely:

boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::ostream&, unsigned int) boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::text_iarchive_impl(std::istream&, unsigned int) boost::archive::text_iarchive_impl<boost::archive::text_oarchive>::~text_oarchive_impl() boost::archive::text_iarchive_impl<boost::archive::text_iarchive>::~text_iarchive_impl() ... boost::archive::archive_exception::~archive_exception()' 

Is there a chance that the library can be used without linking as a header-only library?

For example some undocumented trick or hack?

That would make it more simple to use in some supercomputer clusters and environments where it is not that simply to compile Boost.

#include<sstream> #include<numeric> #include<boost/archive/text_oarchive.hpp> // needs linking #include<boost/archive/text_iarchive.hpp> #include<boost/serialization/vector.hpp> int main(){ std::vector<double> v(10); std::iota(v.begin(), v.end(), 0); std::stringstream ss; { boost::archive::text_oarchive toa(ss); toa << v; } std::vector<double> v2; boost::archive::text_iarchive tia(ss); tia >> v2; assert(v == v2); } 

EDIT: I would be very cool if the library gave the option to be header only, like Boost.Asio does (.)


EDIT2: The author and maintainer of Boost.Serialization rejected the idea of making it header only.

6

Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like