2 fw06412 fw06412 于 2014.11.03 15:45 提问

linux 下使用boost serialization库,编译问题

在linux下使用boost serialization,结果编译不过,折腾了半天也过不去,求大神指导
代码如下,也是网上找的,
#include "boost/serialization/serialization.hpp"
#include "boost/archive/binary_oarchive.hpp"
#include "boost/archive/binary_iarchive.hpp"
#include "boost/serialization/vector.hpp"
#include "boost/serialization/export.hpp"
#include "boost/serialization/extended_type_info_typeid.hpp"
#include "boost/serialization/extended_type_info.hpp"
#include
#include

using namespace std;
using namespace boost::serialization;
typedef struct Demo{
int a;
string s;
vector v;
} Demo;

class CMyData{
private:
friend class boost::serialization::access;

template<class Archive>
void serialize(Archive& ar, const unsigned int version) {
  ar & d.a;
  ar & d.s;
  ar & d.v[0];
}

public:
Demo d;
};

int main(){
string content;
{
string s="helloworld";
CMyData mydata ;
mydata.d.a = 100;
mydata.d.s = s;
mydata.d.v.push_back(5000);

std::ostringstream os;
boost::archive::binary_oarchive oa(os);
oa << mydata;
content = os.str();

}

{
CMyData mydata;
std::istringstream is(content);
boost::archive::binary_iarchive ia(is);
ia >> mydata;
cout<<mydata.d.a<<mydata.d.s<<mydata.d.v[0];
}
return 0;
}
编译命令: g++ -o test boostSerialization3.cpp -I/usr/include/boost -L/usr/lib/libboost_serialization.a boost库已经安装好了

编译结果:
/usr/include/boost/archive/detail/oserializer.hpp: In function ‘void boost::archive::save(Archive&, T&) [with Archive = boost::archive::binary_oarchive, T = CMyData]’:
/usr/include/boost/archive/basic_binary_oarchive.hpp:70: instantiated from ‘void boost::archive::basic_binary_oarchive::save_override(T&, int) [with T = CMyData, Archive = boost::archive::binary_oarchive]’
/usr/include/boost/archive/binary_oarchive.hpp:47: instantiated from ‘void boost::archive::binary_oarchive_impl::save_override(T&, int) [with T = CMyData, Archive = boost::archive::binary_oarchive]’
/usr/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated from ‘Archive& boost::archive::detail::interface_oarchive::operator<<(T&) [with T = CMyData, Archive = boost::archive::binary_oarchive]’
boostSerialization.cpp:45: instantiated from here
/usr/include/boost/archive/detail/oserializer.hpp:567: error: invalid application of ‘sizeof’ to incomplete type ‘boost::STATIC_ASSERTION_FAILURE’
/usr/include/boost/archive/detail/iserializer.hpp: In constructor ‘boost::archive::detail::iserializer::iserializer() [with Archive = boost::archive::binary_iarchive, T = CMyData]’:
/usr/include/boost/archive/detail/iserializer.hpp:146: instantiated from ‘static boost::archive::detail::iserializer& boost::archive::detail::iserializer::instantiate() [with Archive = boost::archive::binary_iarchive, T = CMyData]’
/usr/include/boost/archive/detail/iserializer.hpp:375: instantiated from ‘static void boost::archive::detail::load_non_pointer_type::load_standard::invoke(Archive&, T&) [with Archive = boost::archive::binary_iarchive, T = CMyData]’
/usr/include/boost/archive/detail/iserializer.hpp:425: instantiated from ‘static void boost::archive::detail::load_non_pointer_type::invoke(Archive&, T&) [with Archive = boost::archive::binary_iarchive, T = CMyData]’
/usr/include/boost/archive/detail/iserializer.hpp:572: instantiated from ‘void boost::archive::load(Archive&, T&) [with Archive = boost::archive::binary_iarchive, T = CMyData]’
/usr/include/boost/archive/basic_binary_iarchive.hpp:70: instantiated from ‘void boost::archive::basic_binary_iarchive::load_override(T&, int) [with T = CMyData, Archive = boost::archive::binary_iarchive]’
/usr/include/boost/archive/binary_iarchive.hpp:47: instantiated from ‘void boost::archive::binary_iarchive_impl::load_override(T&, int) [with T = CMyData, Archive = boost::archive::binary_iarchive]’
/usr/include/boost/archive/detail/interface_iarchive.hpp:76: instantiated from ‘Archive& boost::archive::detail::interface_iarchive::operator>>(T&) [with T = CMyData, Archive = boost::archive::binary_iarchive]’
boostSerialization.cpp:53: instantiated from here
/usr/include/boost/archive/detail/iserializer.hpp:114: error: incomplete type ‘boost::serialization::extended_type_info_null’ used in nested name specifier
/usr/include/boost/archive/detail/oserializer.hpp: In constructor ‘boost::archive::detail::oserializer::oserializer() [with Archive = boost::archive::binary_oarchive, T = CMyData]’:
/usr/include/boost/archive/detail/oserializer.hpp:135: instantiated from ‘static boost::archive::detail::oserializer& boost::archive::detail::oserializer::instantiate() [with Archive = boost::archive::binary_oarchive, T = CMyData]’
/usr/include/boost/archive/detail/oserializer.hpp:264: instantiated from ‘static void boost::archive::detail::save_non_pointer_type::save_standard::invoke(Archive&, const T&) [with Archive = boost::archive::binary_oarchive, T = CMyData]’
/usr/include/boost/archive/detail/oserializer.hpp:322: instantiated from ‘static void boost::archive::detail::save_non_pointer_type::invoke(Archive&, const T&) [with Archive = boost::archive::binary_oarchive, T = CMyData]’
/usr/include/boost/archive/detail/oserializer.hpp:536: instantiated from ‘void boost::archive::save(Archive&, const T&) [with Archive = boost::archive::binary_oarchive, T = CMyData]’
/usr/include/boost/archive/detail/oserializer.hpp:568: instantiated from ‘void boost::archive::save(Archive&, T&) [with Archive = boost::archive::binary_oarchive, T = CMyData]’
/usr/include/boost/archive/basic_binary_oarchive.hpp:70: instantiated from ‘void boost::archive::basic_binary_oarchive::save_override(T&, int) [with T = CMyData, Archive = boost::archive::binary_oarchive]’
/usr/include/boost/archive/binary_oarchive.hpp:47: instantiated from ‘void boost::archive::binary_oarchive_impl::save_override(T&, int) [with T = CMyData, Archive = boost::archive::binary_oarchive]’
/usr/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated from ‘Archive& boost::archive::detail::interface_oarchive::operator<<(T&) [with T = CMyData, Archive = boost::archive::binary_oarchive]’
boostSerialization.cpp:45: instantiated from here
/usr/include/boost/archive/detail/oserializer.hpp:107: error: incomplete type ‘boost::serialization::extended_type_info_null’ used in nested name specifier
/usr/include/boost/archive/detail/oserializer.hpp: In member function ‘bool boost::archive::detail::oserializer::is_polymorphic() const [with Archive = boost::archive::binary_oarchive, T = CMyData]’:
boostSerialization.cpp:56: instantiated from here
/usr/include/boost/archive/detail/oserializer.hpp:131: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/serialization/type_info_implementation.hpp:26: error: declaration of ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/archive/detail/oserializer.hpp:132: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/serialization/type_info_implementation.hpp:26: error: declaration of ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/archive/detail/iserializer.hpp: In member function ‘bool boost::archive::detail::iserializer::is_polymorphic() const [with Archive = boost::archive::binary_iarchive, T = CMyData]’:
boostSerialization.cpp:56: instantiated from here
/usr/include/boost/archive/detail/iserializer.hpp:142: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/serialization/type_info_implementation.hpp:26: error: declaration of ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/archive/detail/iserializer.hpp:143: error: invalid use of undefined type ‘struct boost::serialization::extended_type_info_null’
/usr/include/boost/serialization/type_info_implementation.hpp:26: error: declaration of ‘struct boost::serialization::extended_type_info_null’

谁知道啥原因啊,求指导

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!