BGL反序列化的另一个问题
Yet another issue with BGL Deserialization
我正在尝试以图形格式对数据进行序列化和反序列化。我的图的定义如下。
#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;
在我看来,我在序列化过程中没有问题,而在反序列化部分出现了一些问题。事实上,在将这段代码添加到我的源代码之前,我没有链接错误:
#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
}
我试图在这里阅读一些问题并阅读 Boost 手册,但它们并没有解决我的问题。特别是,我有这个错误:
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)
顺便说一句,我正在序列化和反序列化字符串和无符号整数,"native data types" 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;
}
///////
EDIT 是的,我正在将我的源代码链接到 BGL 和 Boost 的序列化。这是通过这部分 CMake 脚本实现的:
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})
由于序列化方法是模板,所以应该放在.h文件中,而不是.cpp部分。
我正在尝试以图形格式对数据进行序列化和反序列化。我的图的定义如下。
#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;
在我看来,我在序列化过程中没有问题,而在反序列化部分出现了一些问题。事实上,在将这段代码添加到我的源代码之前,我没有链接错误:
#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
}
我试图在这里阅读一些问题并阅读 Boost 手册,但它们并没有解决我的问题。特别是,我有这个错误:
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)
顺便说一句,我正在序列化和反序列化字符串和无符号整数,"native data types" 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;
}
///////
EDIT 是的,我正在将我的源代码链接到 BGL 和 Boost 的序列化。这是通过这部分 CMake 脚本实现的:
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})
由于序列化方法是模板,所以应该放在.h文件中,而不是.cpp部分。