gpt4 book ai didi

c++ - 在关闭 RTTI 的情况下 boost 简单类的序列化 (-fno-rtti)

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:34:10 26 4
gpt4 key购买 nike

我正在尝试使用 boost 序列化来序列化具有 Plain-old-Data 类型的简单类。但是,我唯一的要求是不能使用 RTTI。因此,我正在使用 gcc 4.4.1 for ARM Linux 和最新的 Boost 1.47 库使用 -fno-rtti 进行编译。

这是我的类(class):

#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>

class libNemoMemento
{
friend class boost::serialization::access;
private:
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(temperature);
ar & BOOST_SERIALIZATION_NVP(voltage);
ar & BOOST_SERIALIZATION_NVP(bandwidth);
ar & BOOST_SERIALIZATION_NVP(power);
}
int temperature;
unsigned int voltage;
unsigned int bandwidth;
unsigned char power;
public:
libNemoMemento(void) {}
virtual ~libNemoMemento(void) {}
};

我什至还没有实现实际的保存和加载函数(从查看 Boost 文档来看它们似乎非常简单)但我已经收到以下编译器错误:

In file included from /home/me/prebuild/third-party/boost/include/boost/serialization/detail/shared_ptr_132.hpp:29,
from /home/me/third-party/boost/include/boost/serialization/shared_ptr_132.hpp:35,
from /home/me/third-party/boost/include/boost/archive/shared_ptr_helper.hpp:29,
from /home/me/third-party/boost/include/boost/archive/xml_iarchive.hpp:133,
from serialize_test.h:21,
from serialize_test.cpp:15:
/home/me/third-party/boost/include/boost/serialization/detail/shared_count_132.hpp: In member function 'virtual void* boost_132::detail::sp_counted_base_impl<P, D>::get_deleter(const std::type_info&)':
/home/me/third-party/boost/include/boost/serialization/detail/shared_count_132.hpp:274: error: cannot use typeid with -fno-rtti
In file included from /home/me/prebuild/third-party/boost/include/boost/serialization/shared_ptr_132.hpp:35,
from /home/me/prebuild/third-party/boost/include/boost/archive/shared_ptr_helper.hpp:29,
from /home/me/prebuild/third-party/boost/include/boost/archive/xml_iarchive.hpp:133,
from serialize_test.h:21,
from serialize_test.cpp:15:
/home/me/prebuild/third-party/boost/include/boost/serialization/detail/shared_ptr_132.hpp: In function 'D* boost_132::get_deleter(const boost_132::shared_ptr<U>&)':
/home/me/prebuild/third-party/boost/include/boost/serialization/detail/shared_ptr_132.hpp:465: error: cannot use typeid with -fno-rtti
make: *** [all] Error 1

所以..问题是,是否可以在不使用 RTTI 的情况下使用 boost 序列化来序列化这个简单的类?我环顾四周,似乎可以使用一些 boost 宏和机制(#include < boost/serialization/extended_type_info_no_rtti.hpp > 暗示这一点),但我是一个新的 Boost 用户,对于如何进行非常无能为力。

PS:如果我删除 -fno-rtti,我的代码可以正常编译。

最佳答案

关于c++ - 在关闭 RTTI 的情况下 boost 简单类的序列化 (-fno-rtti),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7856277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com