问题正确使用CEREAL_REGISTER_DYNAMIC_INIT在C ++库谷物

问题描述 投票:0回答:1

我搬到了使用库文件,想利用CEREAL_REGISTER_DYNAMIC_INIT的正确。我不知道如果我需要用这个,但我注意到一个问题,有没有在一个单独的DLL正确拿起我cerealization类型之一,并认为这可能帮助。

在accountActions.h我已在该文件的末尾以下内容:

CEREAL_FORCE_DYNAMIC_INIT(mv_clientactions);

在accountActions.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 \源\游戏\ networklayer \ accountactions.cpp(13):错误C2084:函数 'void谷物::详细:: dynamic_init_dummy_mv_accountactions(无效)' 已经具有主体1> C:\ GIT中\ bindstone \源\游戏\ networklayer \ accountactions.h(127):注:参见 'dynamic_init_dummy_mv_accountactions' 以前定义

我仔细检查过,我不使用mv_accountactions其他地方...我不知道什么可能导致这或如何解决它。我想知道如果我甚至需要CEREAL_REGISTER_DYNAMIC_INIT,或者如果有万一使用它一个安全的方式我移动到一个DLL,我只是误用。

建议将不胜感激。

问题这里开:https://github.com/USCiLab/cereal/issues/523

c++ c++11 polymorphism lib cereal
1个回答
1
投票

我似乎与先前失踪CEREAL_DLL_EXPORT定义CEREAL_FORCE_DYNAMIC_INIT已经能够解决这个问题

前(在2017年VS不工作):

//! 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 */
© www.soinside.com 2019 - 2024. All rights reserved.