Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUILD_SHARED_LIBS=ON on Windows does not produce log outputs #302

Closed
DanielKui opened this issue Jun 2, 2023 · 9 comments
Closed

BUILD_SHARED_LIBS=ON on Windows does not produce log outputs #302

DanielKui opened this issue Jun 2, 2023 · 9 comments

Comments

@DanielKui
Copy link

DanielKui commented Jun 2, 2023

cmake -DBUILD_SHARED_LIBS=ON -DQUILL_NO_THREAD_NAME_SUPPORT=ON -DCMAKE_INSTALL_PREFIX=./ ..

I use the above command to generate quill.dll & quill.lib to run official demo example_logging_to_file.cpp, no any contents in example_filehandler.log

However, static lib generated by "cmake .. ", whichi is successfully logging to file.

windows 10 & visual studio 2022

quill_include.zip

Attached my quill included files, I added "QUILL_EXPORT" prefix at the front of necessary functions.

@DanielKui
Copy link
Author

dll.zip
This is my fmt quill debug_x64 dll

@odygrd
Copy link
Owner

odygrd commented Jun 2, 2023

hey, do you have a previous version that was working ?

@odygrd
Copy link
Owner

odygrd commented Jun 2, 2023

I tried to reproduce and when the shared library is used on windows the log file appears empty.
The example that is logging to stdout is working with the shared library on windows.

On linux the shared library is working and output is produced.
Still looking into this

@odygrd odygrd changed the title 2.9.1 BUILD_SHARED_LIBS=ON cannot logging to file BUILD_SHARED_LIBS=ON on Windows does not produce log outputs Jun 2, 2023
@odygrd odygrd changed the title BUILD_SHARED_LIBS=ON on Windows does not produce log outputs BUILD_SHARED_LIBS=ON on Windows does not produce log outputs - workaround Jun 2, 2023
@odygrd odygrd added the help wanted Extra attention is needed label Jun 2, 2023
@odygrd
Copy link
Owner

odygrd commented Jun 2, 2023

It seems that the problem was related to having two same copies of the singleton..
I have made a fix in master 15e2111 can you try and let me know if you have any issues ?

I am compiling with CMAKE arguments :

-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE -DBUILD_SHARED_LIBS=ON -DQUILL_BUILD_EXAMPLES:BOOL=ON -DQUILL_NO_THREAD_NAME_SUPPORT:BOOL=ON

There is another issue when quill is used as a shared library. When the main program finishes and the dll is existing it seems that the backend worker thread just vanishes without executing the _exit() (https://github.com/odygrd/quill/blob/master/quill/include/quill/detail/backend/BackendWorker.h#L311) functions. As a result you may drop log messages.

To avoid dropped messages just call quill::flush() at the end of your main.

@odygrd odygrd changed the title BUILD_SHARED_LIBS=ON on Windows does not produce log outputs - workaround BUILD_SHARED_LIBS=ON on Windows does not produce log outputs Jun 2, 2023
@odygrd odygrd removed the help wanted Extra attention is needed label Jun 2, 2023
@odygrd
Copy link
Owner

odygrd commented Jun 4, 2023

I have fixed the dropping messages on application exit when dll is used.
The examples seem to be working now, Also I ran the whole test suite with quill.dll on windows and it seems good.

Please use 5178dd5 or v2.9.2 when it gets released

To compile on windows use CMake flags

-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE -DBUILD_SHARED_LIBS=ON

@DanielKui
Copy link
Author

DanielKui commented Jun 5, 2023

WIN32
_WINDOWS
NDEBUG
_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
CMAKE_INTDIR="Release"
quill_EXPORTS
QUILL_DLL_EXPORT

The above was my definition in my visual studio.

image

In 2.9.2, I also used "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=TRUE -DBUILD_SHARED_LIBS=ON".
example_filehandler.log still does not produce any logs.
Somehow, x64 debug version, does not even generate example_filehandler.log . x64 release can generate example_filehandler.log , but no contents.
Did I do something wrong?
demo_x64.zip

@odygrd
Copy link
Owner

odygrd commented Jun 5, 2023

examples are working for me as expected on both debug and release modes I just tried again.

Are you building the examples outside of the cmake project ? If yes the examples need to have QUILL_BUILD_SHARED defined (https://github.com/odygrd/quill/blob/master/quill/include/quill/detail/misc/Attributes.h#L102) so #define that before including Quill.h in the examples code or pass it to the compiler

@DanielKui
Copy link
Author

Thanks a lot, it works for me

@odygrd
Copy link
Owner

odygrd commented Jun 6, 2023

hey, glad it is working now. This flag is defined as part of CMake (https://github.com/odygrd/quill/blob/master/quill/CMakeLists.txt#L123) but when building outside of it, it has to be provided

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants