在谷物库中正确使用CEREAL_REGISTER_DYNAMIC_INIT C++问题
Issue correctly using CEREAL_REGISTER_DYNAMIC_INIT in C++ Cereal library
我已经转向使用 lib 文件,并希望正确使用CEREAL_REGISTER_DYNAMIC_INIT。我不知道我是否需要使用它,但我注意到我的一种谷物类型没有在单独的 DLL 中正确拾取的问题,并认为这可能会有所帮助。
在 accountActions.h 中,我在文件末尾有以下内容:
CEREAL_FORCE_DYNAMIC_INIT(mv_clientactions);
在帐户操作中.cpp我在文件顶部附近有以下内容:
#include "clientActions.h"
#include "cereal/cereal.hpp"
#include "cereal/types/base_class.hpp"
#include "cereal/types/polymorphic.hpp"
#include "cereal/archives/adapters.hpp"
#include "cereal/archives/portable_binary.hpp"
#include "cereal/archives/json.hpp"
CEREAL_REGISTER_TYPE(CreatePlayer);
CEREAL_REGISTER_TYPE(LoginRequest);
CEREAL_REGISTER_TYPE(FindMatchRequest);
CEREAL_REGISTER_TYPE(ExpectedPlayersNoted);
CEREAL_REGISTER_DYNAMIC_INIT(mv_accountactions);
假设mv_accountactions只是一个完全组成的字符串。我没有任何库或dll命名,但认为它是用来将这两个单元链接在一起的吗?文档很少,我可能使用不正确。
我得到的错误是这样的:
1>c:\git\bindstone\source\gameetworklayer\accountactions.cpp(13(:错误 C2084:函数"void Cereal::d etail::d ynamic_init_dummy_mv_accountactions(void("已经有一个主体 1>c:\git\bindstone\source\gameetworklayer\accountactions.h(127(: 注意:请参阅前面的"dynamic_init_dummy_mv_accountactions"定义
我已经仔细检查过,没有在其他任何地方使用mv_accountactions......我不知道是什么原因可能导致这种情况或如何解决它。我想知道我是否需要CEREAL_REGISTER_DYNAMIC_INIT,或者是否有一种安全的方式来使用它,以防我确实移动到 DLL 并且我只是滥用它。
建议将不胜感激。
此处打开的问题:https://github.com/USCiLab/cereal/issues/523
我似乎能够通过定义具有先前缺失CEREAL_DLL_EXPORT的CEREAL_FORCE_DYNAMIC_INIT来解决此问题
之前(在VS 2017中不起作用(:
//! Forces dynamic initialization of polymorphic support in a
//! previously registered source file
/*! @sa CEREAL_REGISTER_DYNAMIC_INIT
See CEREAL_REGISTER_DYNAMIC_INIT for detailed explanation
of how this macro should be used. The name used should
match that for CEREAL_REGISTER_DYNAMIC_INIT. */
#define CEREAL_FORCE_DYNAMIC_INIT(LibName)
namespace cereal {
namespace detail {
void dynamic_init_dummy_##LibName();
} /* end detail */
namespace {
void dynamic_init_##LibName()
{
::cereal::detail::dynamic_init_dummy_##LibName();
}
} } /* end namespaces */
之后(固定(:
//! Forces dynamic initialization of polymorphic support in a
//! previously registered source file
/*! @sa CEREAL_REGISTER_DYNAMIC_INIT
See CEREAL_REGISTER_DYNAMIC_INIT for detailed explanation
of how this macro should be used. The name used should
match that for CEREAL_REGISTER_DYNAMIC_INIT. */
#define CEREAL_FORCE_DYNAMIC_INIT(LibName)
namespace cereal {
namespace detail {
void CEREAL_DLL_EXPORT dynamic_init_dummy_##LibName();
} /* end detail */
namespace {
void dynamic_init_##LibName()
{
::cereal::detail::dynamic_init_dummy_##LibName();
}
} } /* end namespaces */
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 设置使用 Cereal 序列化库时可以在序列化函数中访问的属性
- 注册 Clang 检查器时出错:"out-of-line-definition of register"
- Protobuf的反序列化功能之一可以使用Cereal重新创建吗?
- Cereal 找不到任何输出序列化函数
- Xcode - 如何使用"-fexhaustive-register-search"进行编译 - 链接器崩溃需要
- 使用 Cereal 反序列化 JSON 字符串
- C++"Register a class"是什么
- 替换不推荐使用的register关键字C++11
- 在 64 位 Windows 7 上使用 MinGW 进行编译时"Error: bad register name `%rax'"
- 使用 TCP 套接字'register'客户端进行 UDP 连接?
- 覆盖register关键字
- Cereal不支持原始指针
- 成功编译节点模块并"Module did not self-register."
- 我什么时候会在C++中使用const volatile、register volatible和static volati
- Arduino 错误"unable to find a register to spill in class 'NO_REGS'"
- 与register关键字关联的其他语义
- C++/Cereal:从 JSON 反序列化为自己类时的异常
- 编译器行为和"register storage class specifier is deprecated"
- 关闭"'register' storage class specifier is deprecated"警告