Yet another issue with BGL Deserialization

I'm trying to both serialize and deserialize the data in a graph format. The definition of my graph is the following one. #include <boost/graph/adjacency_list.hpp> #include <boost/graph/directed_graph.hpp> #include <boost/graph/adj_list_serialize.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/binary_object.hpp> class VFull { public: VFull(); unsigned int id, hash, year; std::string ip, organization; VFull(unsigned int id, unsigned int hash, unsigned int year, std::string ip, std::string organization); template<class Archive> void serialize(Archive & ar, const unsigned int version); }; class EFull { public: EFull(); template<class Archive> void serialize(Archive & ar, const unsigned int version); }; class GFull { public: template<class Archive> void serialize(Archive & ar, const unsigned int version); }; //Defining the graph data structure. Using the vecS specification typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,VFull,EFull,GFull> graph_t; typedef boost::graph_traits<graph_t>::vertex_descriptor result_vertex_descriptor; typedef boost::graph_traits<graph_t>::edge_descriptor result_edge_descriptor; It seems to me that I have no problems in the serialization process, while I have some issues in the deserialization part. In fact, I have no linking errors until this piece of code is added to my source: #include <iomanip> #include <iostream> #include <fstream> { std::ifstream file(path,std::ios_base::binary); boost::archive::binary_iarchive store{file}; store >> graph; // Deserialization part that triggers the error } I tried to read some questions here and to read the Boost manual, but they didn't solve my problem. In particular, I have this error: Undefined symbols for architecture x86_64: "void EFull::serialize<boost::archive::binary_iarchive>(boost::archive::binary_iarchive&, unsigned int)", referenced from: void boost::serialization::access::serialize<boost::archive::binary_iarchive, EFull>(boost::archive::binary_iarchive&, EFull&, unsigned int) in boostOthers.cpp.o "void GFull::serialize<boost::archive::binary_iarchive>(boost::archive::binary_iarchive&, unsigned int)", referenced from: void boost::serialization::access::serialize<boost::archive::binary_iarchive, GFull>(boost::archive::binary_iarchive&, GFull&, unsigned int) in boostOthers.cpp.o "void VFull::serialize<boost::archive::binary_iarchive>(boost::archive::binary_iarchive&, unsigned int)", referenced from: void boost::serialization::access::serialize<boost::archive::binary_iarchive, VFull>(boost::archive::binary_iarchive&, VFull&, unsigned int) in boostOthers.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) By the way, I'm serializing and deserializing strings and unsigned ints, "native data types" that seems to be supported by boost: //VERTICES VFull::VFull() { } VFull::VFull(unsigned int i, unsigned int h, unsigned int y, std::string p, std::string o) : id{i}, hash{h}, year{y}, ip{p}, organization{o} { } template<class Archive> void VFull::serialize(Archive &ar, const unsigned int version) { ar & 'i'; ar & id; ar & 'h'; ar & hash; ar & '1'; ar & ip; ar & '2'; ar & organization; ar & '3'; ar & year; ar & '/'; } /////// //EDGES EFull::EFull() { } template<class Archive> void EFull::serialize(Archive &ar, const unsigned int version) { char waste = 'e'; ar & waste; } /////// //GRAPH SIGNATURE template<class Archive> void GFull::serialize(Archive &ar, const unsigned int version) { std::string waste = "GBLS"; ar & waste; } /////// Yes, I am linking my source code to both BGL and Boost's serialization. This is acheived through this part of CMake script: find_package( Boost REQUIRED COMPONENTS graph serialization ) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED OFF) INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIRS} ..some other stuff..) TARGET_LINK_LIBRARIES(mycode ${Boost_LIBRARIES})

On 8/28/16 3:41 AM, giacomo@openmailbox.org wrote:
I'm trying to both serialize and deserialize the data in a graph format. The definition of my graph is the following one.
#include <boost/graph/adjacency_list.hpp> #include <boost/graph/directed_graph.hpp> #include <boost/graph/adj_list_serialize.hpp> #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/binary_object.hpp>
class VFull { public: VFull(); unsigned int id, hash, year; std::string ip, organization; VFull(unsigned int id, unsigned int hash, unsigned int year, std::string ip, std::string organization); template<class Archive> void serialize(Archive & ar, const unsigned int version); };
class EFull { public: EFull(); template<class Archive> void serialize(Archive & ar, const unsigned int version); };
class GFull { public: template<class Archive> void serialize(Archive & ar, const unsigned int version); };
//Defining the graph data structure. Using the vecS specification typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS,VFull,EFull,GFull> graph_t; typedef boost::graph_traits<graph_t>::vertex_descriptor result_vertex_descriptor; typedef boost::graph_traits<graph_t>::edge_descriptor result_edge_descriptor;
It seems to me that I have no problems in the serialization process, while I have some issues in the deserialization part. In fact, I have no linking errors until this piece of code is added to my source:
#include <iomanip> #include <iostream> #include <fstream> { std::ifstream file(path,std::ios_base::binary); boost::archive::binary_iarchive store{file}; store >> graph; // Deserialization part that triggers the error }
Consider making a smaller/simpler test program to verify that things work independently of the graph library. In other words, what happens with the following example: #include <boost/archive/binary_oarchive.hpp> #include <boost/archive/binary_iarchive.hpp> #include <boost/serialization/string.hpp> #include <boost/serialization/binary_object.hpp> #include "full.hpp" // VFull etc... #include "full.cpp" // VFull::void serialize(Archive &ar, const unsigned int version {...} definitions #include <fstream> int main(){ VFull vf{...}; // create test instance of VFull // ... same for EFull, GFull { std::ifstream f(path,std::ios_base::binary); boost::archive::binary_oarchive oa{f}; oa << vf << ef << gf; // exiting context closes archive and files } { std::ifstream f(path,std::ios_base::binary); boost::archive::binary_iarchive ia{f}; VFull in_vf; // create test instance of VFull // ... same for EFull, GFull ia >> in_vf >> in_ef >> in_gf; if(in_vf != vf) exit(1); // same for ef and gf // exiting context closes archive and files } exit (0); } Making this test program will exclude the graph library from the equation. So if you have problems getting this to compile, link or run correctly, we can focus exclusively on the serialization library usage. If this does work as expected, one can delve into the serialization implementation in the graph library Robert Ramey
participants (2)
-
giacomoï¼ openmailbox.org
-
Robert Ramey