0
votes

i have writing a map to an xml file using the below code , but i can't successfully compile the code , i am actually trying to compile this on mac sierras terminal .

Would you please advice what may have went wrong

#include <fstream>
#include <boost/serialization/map.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/archive/xml_oarchive.hpp>
using namespace std;

class MyConnections  
{
public:
MyConnections()
{
   m_connections["one"]= "one";
}

template<class archive>
void serialize(archive& ar, const unsigned int version)
{
    using boost::serialization::make_nvp;
    ar & make_nvp("Connections", m_connections);
}

public:
 map<string,string> m_connections ;
}; 

int main(int argc, char* argv[])
{
std::ofstream ofs("output.xml");
const MyConnections conn;

boost::archive::xml_oarchive xml(ofs);
xml << boost::serialization::make_nvp("Connections", conn);
}

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Full Error is really huge

Undefined symbols for architecture x86_64: "boost::serialization::typeid_system::extended_type_info_typeid_0::type_register(std::type_info const&)", referenced from: boost::serialization::extended_type_info_typeid::extended_type_info_typeid() in teee-a553d7.o boost::serialization::extended_type_info_typeid, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >, std::__1::less, std::__1::allocator > >, std::__1::allocator, std::__1::allocator > const, std::__1::basic_string, std::__1::allocator > > > > >::extended_type_info_typeid() in teee-a553d7.o boost::serialization::extended_type_info_typeid, std::__1::allocator > const, std::__1::basic_string, std::__1::allocator > > >::extended_type_info_typeid() in teee-a553d7.o "boost::serialization::typeid_system::extended_type_info_typeid_0::type_unregister()", referenced from: boost::serialization::extended_type_info_typeid::~extended_type_info_typeid() in teee-a553d7.o boost::serialization::extended_type_info_typeid, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >, std::__1::less, std::__1::allocator > >, std::__1::allocator, std::__1::allocator > const, std::__1::basic_string, std::__1::allocator > > > > >::~extended_type_info_typeid() in teee-a553d7.o boost::serialization::extended_type_info_typeid, std::__1::allocator > const, std::__1::basic_string, std::__1::allocator > > >::~extended_type_info_typeid() in teee-a553d7.o "boost::serialization::typeid_system::extended_type_info_typeid_0::extended_type_info_typeid_0(char const*)", referenced from: boost::serialization::extended_type_info_typeid::extended_type_info_typeid() in teee-a553d7.o boost::serialization::extended_type_info_typeid, std::__1::allocator >, std::__1::basic_string, std::__1::allocator >, std::__1::less, std::__1::allocator > >, std::__1::allocator, std::__1::allocator > const, std::__1::basic_string, std::__1::allocator > > > > >::extended_type_info_typeid() in teee-a553d7.o

1
Boost serialization is not a header-only library, so you have to specify boost lib path and possibly also .lib files of boost serialization on the linker command-line. I'm a Windows guy so I can't give more specific help for that.zett42

1 Answers

0
votes
clang++-3.8 boost_serialization_test.cpp -lboost_serialization

In section "Header-Only Libraries" of official "Getting started" for Unixes, read about what libraries are built separately. Also read section on linking and libraries naming.