-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Is the example about how to use spdlog in DLLs updated? #1598
Comments
The wiki is written with the assumption that you are using a header-only spdlog in your shared library and application. When spdlog is built as a shared library, a single registry is shared between multiple applications. The error is caused by the presence of the following two codes that register a logger with the same name for a single registry. |
Thanks @tt4g for the feedback. I think I understood the problem with registering 2 loggers with the same name at two different points. I made some modifications in the master branch of my toy project and I could get the expected behaviour. However, when consuming spdlog as header-only, and the following the example from the wiki page, I do not achieve the desired behaviour. I get the same exception indicating that the logger with the same name already exists. (conan) luis@desktopUbuntu:/media/linux/programming/spdlogExample/buildDebug$ rm -rf *
(conan) luis@desktopUbuntu:/media/linux/programming/spdlogExample/buildDebug$ cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON ../
-- The CXX compiler identification is GNU 9.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /media/linux/programming/spdlogExample/buildDebug
(conan) luis@desktopUbuntu:/media/linux/programming/spdlogExample/buildDebug$ make -j4
Scanning dependencies of target myLib
[ 25%] Building CXX object lib/CMakeFiles/myLib.dir/src/myLib.cpp.o
[ 50%] Linking CXX shared library libmyLib.so
[ 50%] Built target myLib
Scanning dependencies of target myApp
[ 75%] Building CXX object app/CMakeFiles/myApp.dir/myApp.cpp.o
[100%] Linking CXX executable ../bin/myApp
[100%] Built target myApp
(conan) luis@desktopUbuntu:/media/linux/programming/spdlogExample/buildDebug$ bin/myApp
Hello world!
[2020-06-19 19:43:37.566] [example] [debug] test::message 1
terminate called after throwing an instance of 'spdlog::spdlog_ex'
what(): logger with name 'example' already exists
Abortado (`core' generado) I am wondering if the problem could come from the existing comment in the first line of the main function from your wiki page: int main()
{
// We assume that we load the library here
...
// Let's use the library
} The first comment about loading the library ... is it referring to doing manual loading of dynamic libraries? Or should it also work with the automatic linking? |
Both dynamic and automatic links should have the same result. If you make the following changes and then build the shared library myLib, it should work the same as the Wiki. https://github.com/piponazo/spdlogExample/blob/master/conanfile.py#L9: - self.options['spdlog'].shared = True
+ self.options['spdlog'].shared = False and define CMake variable |
The past day I should have skipped something ... I just tried again with the changes you proposed and I do not get the exception anymore on Windows10 + MSVC2019. I have left the working example in the same repository under the branch spdlogAsHeaderOnly. https://github.com/piponazo/spdlogExample/tree/spdlogAsHeaderOnly Thanks for your help. I am closing now the issue 👍 |
Hi,
I have been trying to follow the example to use spdlog in DLLs from the wiki, but I could not manage to make things work:
https://github.com/gabime/spdlog/wiki/How-to-use-spdlog-in-DLLs
I have created a mini repository where it is very easy to reproduce the issue:
https://github.com/piponazo/spdlogExample
In this repository I am bringing the spdlog dependency with conan from their conan-center repository:
https://conan.io/center/spdlog/1.6.1/?user=_&channel=_
There are the commands I run to reproduce the issue:
I have tried many different things:
But in all the cases, I get the same problem. I kindly ask you to help me to find the root cause of this problem. If we find it, I would be happy to contribute with some documentation to make things more clear in the wiki.
Cheers
The text was updated successfully, but these errors were encountered: