Quill as a DLL: Sinks Between DLLs. #584
-
Hello! The engineers at my work and I really love Quill. We have a need to use Quill across DLLs. I have built Quill as a DLL and it works when using it in one DLL. If I try to LOG from two different DLLs using the same logger, it will work until the memory is freed (when calling FreeLibrary). I believe this is because the Sinks are made with a shared_ptr. Shared pointers are difficult to work with across DLLs. Is there a way to get a console as a raw/standard pointer or another way to handle this so we can keep using Quill in this way without crashing when releasing memory? Thank you for your insight! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Hey, the sinks are managed via shared_ptr, ensuring that when all Logger objects holding a reference to a sink are removed, the sink is automatically destructed, and any underlying files are closed properly. Would you mind sharing a quick example of your setup, including the use of FreeLibrary? This would help me reproduce the issue on my end, and I’ll try to look into finding a fix |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick follow-up. Yes, it would be really helpful if you could recreate the issue with a simple example that I can use to reproduce it on my end. I’ve attempted to replicate the behaviour in this example here: https://github.com/odygrd/quill/blob/shared_lib_example/examples/shared_library/example_shared.cpp However, I haven't been able to reproduce the crash yet. When you have some time, could you take a look at the example and let me know if there's anything I should adjust to better reflect your setup? Any additional insights would be much appreciated! |
Beta Was this translation helpful? Give feedback.
-
This is fixed in commit 5567063 and latest release You still have to call case DLL_PROCESS_DETACH:
global_logger_a->flush_log();
break; |
Beta Was this translation helpful? Give feedback.
I’m not entirely sure if /MD linking is related—I came across that suggestion somewhere but don’t have much experience working with DLLs.
One thing I did in the example was to call flush_log in DllMain for each module, as it was crashing when a module was freed with pending logs.
quill/examples/shared_library/test_module/include/test_module/test_module.cpp
Line 21 in a731232
Maybe give that a try and see if it helps. If not, feel free to tweak the example to better match your setup.