Can Boost serialization be used as a header-only library?
Below is a minimal example of using the large Boost.Serialization library .
In order to compile a library, I need to link against the precompiled library boost_serialization
.
$ c++ -std=c++11 example.cpp -o example.x -lboost_serialization
^^^^^^^^^^^^^^^^^^^^^
The library is heavily shaded, although the complex inner code (function body) is pretty simple. There are only a few links that need to be referenced, 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 the library can be used without reference as a header-only library?
For example, some undocumented trick or hack?
This would make it easier to use in some supercomputing clusters and environments where it is not easy 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 : It would be really great for me if the library only allowed a header like Boost.Asio ( stackoverflow )
EDIT2 . The author and maintainer of Boost.Serialization rejected the idea of creating just a header. https://github.com/boostorg/serialization/issues/71
source to share
No one has answered this question yet