2

and using boost serialization I have been getting a lot of errors using the serialization header files, like this:

/home/saikumar/Downloads/boost_1_61_0/boost/archive/text_iarchive.hpp:117: error: undefined reference to `boost::archive::text_iarchive_impl::text_iarchive_impl(std::istream&, unsigned int)'

I tried every possible links in stackoverflow (1, 2, 3, and several others).

They say to use LIBS += -lboost_system or others but boost documentation says it is a header only library Boost setup, which means it doesn't require any library linkage and even if I try searching for that library in boost folder, I can not find it.

I followed the same steps performed in boost setup process but I am not able to find any thing. Here is the code that i am testing it on:

#include <fstream>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include <vector>

class test
{
public:

    std::vector<int> test1;
    std::string test2;

    test()
    {
    }

    test(std::vector<int> h, std::string i):test1(h), test2(i)
    {
    }
private:
    friend class boost::serialization::access;
    template<class Archive> void serialize(Archive & ar, const unsigned int version)
    {
        ar & test1;
        ar & test2;
    }
};

int main(int argc, char *argv[])
{
    test obj;

    obj.test1.push_back(1);
    obj.test1.push_back(3);
    obj.test1.push_back(6);
    obj.test1.push_back(74);
    obj.test1.push_back(43);
    obj.test1.push_back(12);
    obj.test1.push_back(8);
    obj.test1.push_back(13);

    obj.test2 ="jsahdjfkadshflkssfjdslfk";


    std::ofstream file("myfile.FILE");
    boost::archive::text_oarchive oo(file);
    oo<<obj;

    test obj1;

    std::ifstream ifs("myfile.FILE");
    boost::archive::text_iarchive ia(ifs);
    ia >> obj1;

    return 0;
}

2 Answers 2

3

boost/archive/text_iarchive.hpp is part of Boost.Serialization and that definitely is not a header-only library.

The library is normally called boost_serialization (libboost_serialization.so), plus you also need boost_wserialization (libboost_wserialization.so) if you want to use wchar_t with it.

2

You need to link against boost::serialization. Add -lboost_serialization to your LIBS.

LIBS += -lboost_serialization

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.