boost :: binary_wiarchive给出链接错误

时间:2016-05-13 07:35:47

标签: c++ serialization boost boost-serialization

我正在使用:

  • Visual Studio 2013 Update 5;
  • 提升1.57.0;使用boost站点文档构建,但address-model=64标志除外(我需要创建64位应用程序)。

我已经创建了一个用于测试序列化的新项目。这段代码编译得很好:

#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <fstream>

struct MyStruct {
  double data;

private:

  friend class boost::serialization::access;

private:

  template<class Archive>
  void serialize(Archive & archive, const unsigned int version) {
    archive & BOOST_SERIALIZATION_NVP(data);
  };
};

int main() {
  std::ifstream fileStream("myfile.xml");
  boost::archive::binary_iarchive archive(fileStream);
  MyStruct myStruct;
  archive >> BOOST_SERIALIZATION_NVP(myStruct);
  return 0;
}

但是,如果我传递给宽字符,我会获得链接错误。

此代码:

#include <boost/archive/binary_wiarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <fstream>

struct MyStruct {
  double data;

private:

  friend class boost::serialization::access;

private:

  template<class Archive>
  void serialize(Archive & archive, const unsigned int version) {
    archive & BOOST_SERIALIZATION_NVP(data);
  };
};

int main() {
  std::wifstream fileStream(L"myfile.xml");
  boost::archive::binary_wiarchive archive(fileStream);
  MyStruct myStruct;
  archive >> BOOST_SERIALIZATION_NVP(myStruct);
  return 0;
}

给我这些链接错误:

1>main.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::archive::basic_binary_iprimitive<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::init(void)" (?init@?$basic_binary_iprimitive@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAAXXZ) referenced in function "protected: void __cdecl boost::archive::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::init(unsigned int)" (?init@?$binary_iarchive_impl@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAAXI@Z)
1>main.obj : error LNK2019: unresolved external symbol "protected: __cdecl boost::archive::basic_binary_iprimitive<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::basic_binary_iprimitive<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >(class std::basic_streambuf<wchar_t,struct std::char_traits<wchar_t> > &,bool)" (??0?$basic_binary_iprimitive@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAA@AEAV?$basic_streambuf@_WU?$char_traits@_W@std@@@std@@_N@Z) referenced in function "protected: __cdecl boost::archive::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >(class std::basic_istream<wchar_t,struct std::char_traits<wchar_t> > &,unsigned int)" (??0?$binary_iarchive_impl@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAA@AEAV?$basic_istream@_WU?$char_traits@_W@std@@@std@@I@Z)
1>main.obj : error LNK2019: unresolved external symbol "protected: __cdecl boost::archive::basic_binary_iprimitive<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::~basic_binary_iprimitive<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >(void)" (??1?$basic_binary_iprimitive@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAA@XZ) referenced in function "int `protected: __cdecl boost::archive::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >(class std::basic_istream<wchar_t,struct std::char_traits<wchar_t> > &,unsigned int)'::`1'::dtor$0" (?dtor$0@?0???0?$binary_iarchive_impl@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAA@AEAV?$basic_istream@_WU?$char_traits@_W@std@@@std@@I@Z@4HA)
1>main.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::archive::basic_binary_iarchive<class boost::archive::binary_wiarchive>::load_override(struct boost::archive::class_name_type &,int)" (?load_override@?$basic_binary_iarchive@Vbinary_wiarchive@archive@boost@@@archive@boost@@IEAAXAEAUclass_name_type@23@H@Z) referenced in function "protected: void __cdecl boost::archive::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::load_override<struct boost::archive::class_name_type>(struct boost::archive::class_name_type &,int)" (??$load_override@Uclass_name_type@archive@boost@@@?$binary_iarchive_impl@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAAXAEAUclass_name_type@12@H@Z)
1>main.obj : error LNK2019: unresolved external symbol "protected: void __cdecl boost::archive::basic_binary_iarchive<class boost::archive::binary_wiarchive>::init(void)" (?init@?$basic_binary_iarchive@Vbinary_wiarchive@archive@boost@@@archive@boost@@IEAAXXZ) referenced in function "protected: void __cdecl boost::archive::binary_iarchive_impl<class boost::archive::binary_wiarchive,wchar_t,struct std::char_traits<wchar_t> >::init(unsigned int)" (?init@?$binary_iarchive_impl@Vbinary_wiarchive@archive@boost@@_WU?$char_traits@_W@std@@@archive@boost@@IEAAXI@Z)
1>path\QtSerializationSample.exe : fatal error LNK1120: 5 unresolved externals

我在another reply中看到我可以使用binary_iarchive来保存宽字符串,但我想使用wifstream以便由于其他原因,在代码中保持一致性。

有没有办法正确使用binary_wiarchive

0 个答案:

没有答案