我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
I met a question when using boost::serialization, my code works fine in linux, but met a exception in windows
我正在尝试使用 boost 保存 ORB-SLAM 构建的地图,代码在 Linux 中运行良好,但是当我将其移动到 Windows 时,我在加载数据时遇到了异常。下面是我代码的一部分,这是一个大项目,所以我只显示相关的代码。
.h 中的一些代码
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
boost::serialization::split_member(ar, *this, version);
}
template<class Archive>
void save(Archive & ar, const unsigned int version) const;
template<class Archive>
void load(Archive & ar, const unsigned int version);
CPP 简介
template<class Archive>
void Map::load(Archive & ar, const unsigned int version)
{
unsigned int test_data;
int nItems;
ar & nItems;
cout << "{INFO}mspMapPoints size = " << nItems << endl;
for (int i = 0; i < nItems; ++i) {
MapPoint* pMapPoint = new MapPoint();
ar & *pMapPoint;
mspMapPoints.insert(pMapPoint);
}
ar & nItems;
cout << "{INFO}mspKeyFrames size = " << nItems << endl;
for (int i = 0; i < nItems; ++i) {
KeyFrame* pKeyFrame = new KeyFrame;
ar & *pKeyFrame;
mspKeyFrames.insert(pKeyFrame);
}
ar & nItems;
cout << "{INFO}mvpKeyFrameOrigins size = " << nItems << endl;
for (int i = 0; i < nItems; ++i) {
KeyFrame* pKeyFrame = new KeyFrame;
ar & *pKeyFrame;
/* TODO : VerifyHere*/
mvpKeyFrameOrigins.push_back(*mspKeyFrames.begin());
}
ar & const_cast<long unsigned int &> (mnMaxKFid);
ar & test_data;
if (test_data == TEST_DATA)
cout <<">>Map Loading Validated as True" << endl;
else
cout <<"ERROR Map Loading Validated as False: Got -" << test_data << " :( Check Load Save sequence" << endl;
}
调用函数如下:
void System::LoadMap(const string &filename)
{
{
std::ifstream is(filename,std::ios::binary);
boost::archive::binary_iarchive ia(is, boost::archive::no_header);
//ia >> mpKeyFrameDatabase;
ia >> mpMap;
}
cout << endl << filename <<" : Map Loaded!" << endl;
}
void System::SaveMap(const string &filename)
{
std::ofstream os(filename,std::ios::binary);
{
boost::archive::binary_oarchive oa(os, boost::archive::no_header);
//oa << mpKeyFrameDatabase;
oa << mpMap;
}
cout << endl << "Map saved to " << filename << endl;
}
在 Linux 中保存和加载都可以,但加载只会抛出 boost::archive::archive_exception 问题,没有告诉我任何细节。
您应该仅显示相关代码。特别是,它应该显示您的存档选择。另外,您从未告诉我们/what/不起作用,但我的猜测是您正在Windows侧加载保存在linux端的存档?
二进制存档格式不可移植。因此,请务必避免这种情况或使用尝试便携的直接替代品:https://github.com/mika-fischer/eos-portable-archive
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 如何在linux终端中同时编译和运行c++代码
- 在Linux for Windows上编译C++代码时出错
- 找不到Linux Visual Studio代码C++文件
- 是否可以在Linux上使用.Net Core 3.1创建C++/CLI代码的C#DLL
- 在 Linux 群集上运行 Windows C++代码
- [longjmp/setjmp]c++ 相同的代码窗口有异常 Linux 没有错误并且运行良好
- 在 Azure DevOps 构建管道中使用英特尔C++编译器为 Linux 环境构建C++代码
- g++ 9.2.1 (Linux) 会导致 seg 错误,但 Windows 上的代码块不会
- 我在使用 boost::serialization 时遇到了一个问题,我的代码在 Linux 中运行良好,但在 Wind
- 使用 execv 从C++代码执行的 Linux 脚本失败
- 如何从支持linux/mac操作系统的第三方代码为我的c#项目创建dll
- linux mint进程上的代码块已终止,状态为-1
- 在 RedHat Linux Enterprise Developer Workstation 上编译 C++17 代码
- 如何在 Linux 中获取本地代码页?
- popen() 如何工作以及如何在 Linux 上实现它到 C++ 代码中
- C++代码在 Linux 上按预期工作,但在 Windows 上则不然
- 为什么我的C 代码在Linux上运行,而在Windows上不运行,是否有RAM内存的问题
- C/C++,如何在CLI中为下载进度编写代码?Linux
- 使用哪个命令在C++代码 [Linux] 中执行程序