0

I have a C++ desktop app that can log messages using the 'spdlog' library (https://github.com/gabime/spdlog). Now, I'd like to use the same logger from a dynamically loaded DLL. However, when I try to use spdlog from the DLL, I get a crash.

How can I setup the dynamically-loaded DLL to use the same logger as the main app?

Dess
  • 2,064
  • 19
  • 35

1 Answers1

0

I found one possible cause of the problem.

spdlog is header-only. If you have two copies of the log, one in your application and one in your dll, and you pass dynamic references from the application's copy of spdlog to your dll's copy, and you compiled the application and the dll with different options, you can end up with two incompatible definitions of spdlog's class functions.

Particular offending options:

/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.

Each of these options changes the interpretation of every declaration in the files being processed. Therefore, the one definition rule has been violated, with undefined behavior as the penalty.

Joshua
  • 40,822
  • 8
  • 72
  • 132