How to get boost :: serialization to work?

I am working on ubuntu 12.04LTS and am using clang 3.4.

I have a CMake project and want to use boost serialization library. I downloaded boost 1.55.0 from SourceForge.

The project folder tree is as follows:

MyProject
    |    Source
    |       |    main.cpp
    |       |    CMakeLists.txt
    |    Build
    |    Libraries
    |       |    Boost1p55p0
    |       |         |    boost
    |       |         |    ...other boost data
    |       |         |    build
    |       |         |       |    include
    |       |         |       |    lib

So, in the directory, Boost1p55p0I created a new directory build, so bootstrap looked like this:

./bootstrap.sh --prefix=build/

Then i did

./b2

and

./b2 install

So a minimal non-working example:

CMakeLists.txt:

cmake_minimum_required (VERSION 2.6)

set( CMAKE_C_COMPILER clang )
set( CMAKE_CXX_COMPILER clang++ )
set( CMAKE_LINKER llvm-link )

project (Test)
include_directories( ${PROJECT_SOURCE_DIR} ../Libraries/Boost1p55p0/build/include )

set( sources ${sources} main )

add_executable(Test ${sources})

set( OperatingSystem "Linux" )
set( CMAKE_CXX_FLAGS "-std=c++11" )

find_library( PATH_TO_BoostSerialization boost_serialization ../Libraries/Boost1p55p0/build/lib/ )

target_link_libraries (Test ${PATH_TO_BoostSerialization})

main.cpp (from the tutorial , but with xml archives):

#include <fstream>
#include <string>

// include headers that implement a archive in simple text format
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>

/////////////////////////////////////////////////////////////
// gps coordinate
//
// illustrates serialization for a simple type
//
class gps_position
{
    private:
        friend class boost::serialization::access;

        template<class Archive>
        void serialize(Archive & ar, const unsigned int version)
        {
            ar & degrees;
            ar & minutes;
            ar & seconds;
        }
        int degrees;
        int minutes;
        float seconds;
    public:
        gps_position(){};
        gps_position(int d, int m, float s) :
            degrees(d), minutes(m), seconds(s){}
};

int main() {
    std::string inFileName = "testIn.xml";
    std::string outFileName = "testOut.xml";
    // create and open a character archive for output
    std::ofstream ofs(outFileName);

    // create class instance
    const gps_position g(35, 59, 24.567f);

    // save data to archive
    {
        boost::archive::xml_oarchive oa(ofs);
        // write class instance to archive
        oa << g;
    }

    return 0;
}

And now I get the following compiler error:

[cut off directory tree here]Boost1p55p0/build/include/boost/archive/basic_xml_oarchive.hpp:92:9: error: no matching function for call to
  'assertion_failed'
    BOOST_MPL_ASSERT((serialization::is_wrapper< T >));
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[cut off directory tree here]Boost1p55p0/build/include/boost/mpl/assert.hpp:287:11: note: expanded from macro 'BOOST_MPL_ASSERT'
      boost::mpl::assertion_failed<false>( \

I do not know where the error is. I don’t know if I know.

Thank you very much in advance

+4
source share
1

, , , :

main.cpp( , xml-)

Xml !

XML- . XML , " ", . XML , . - , .

, , --. nvp.hpp. , const char *, XML. -. , . , -, , , . , - , .

, demo_xml.cpp, :

template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
    ar & BOOST_SERIALIZATION_NVP(degrees);
    ar & BOOST_SERIALIZATION_NVP(minutes);
    ar & BOOST_SERIALIZATION_NVP(seconds);
}

boost::archive::xml_oarchive oa(ofs);
// write class instance to archive
oa << BOOST_SERIALIZATION_NVP(g);

Live on Coliru

:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE boost_serialization>
<boost_serialization signature="serialization::archive" version="10">
<g class_id="0" tracking_level="0" version="0">
    <degrees>35</degrees>
    <minutes>59</minutes>
    <seconds>24.566999</seconds>
</g>
</boost_serialization>
+5

All Articles