【问题标题】:Log from a dynamically loaded library从动态加载的库中记录
【发布时间】:2018-06-24 20:12:58
【问题描述】:

我有一个 C++ 桌面应用程序,它可以使用“spdlog”库 (https://github.com/gabime/spdlog) 记录消息。现在,我想从动态加载的 DLL 中使用相同的记录器。但是,当我尝试使用 DLL 中的 spdlog 时,我遇到了崩溃。

如何设置动态加载的 DLL 以使用与主应用相同的记录器?

【问题讨论】:

  • 也许在 DLL 中您尝试使用已经注册的名称注册记录器?

标签: c++ windows dll spdlog


【解决方案1】:

我发现了一个可能的问题原因。

spdlog 仅是标题。如果您有两个日志副本,一个在您的应用程序中,一个在您的 dll 中,并且您将动态引用从应用程序的 spdlog 副本传递到您的 dll 副本,并且您使用不同的选项编译了应用程序和 dll,您可以结束增加了两个不兼容的 spdlog 类函数定义。

特定的违规选项:

/Gd     Uses the __cdecl calling convention (x86 only).
/GR     Enables run-time type information (RTTI).
/Gr     Uses the __fastcall calling convention (x86 only).
/Gv     Uses the __vectorcall calling convention. (x86 and x64 only)
/vmm    Declares multiple inheritance.
/vms    Declares single inheritance.
/vmv    Declares virtual inheritance.
/vmb    Uses best base for pointers to members.
/vmg    Uses full generality for pointers to members.
/Zp     Packs structure members.

这些选项中的每一个都会更改正在处理的文件中每个声明的解释。因此,违反了单一定义规则,以未定义的行为作为惩罚。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-23
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2019-02-25
    • 1970-01-01
    相关资源
    最近更新 更多