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

"Shared" example not working on Windows/MinGW #245

Open
TeknoVenus opened this issue Apr 1, 2023 · 3 comments
Open

"Shared" example not working on Windows/MinGW #245

TeknoVenus opened this issue Apr 1, 2023 · 3 comments
Assignees
Labels

Comments

@TeknoVenus
Copy link

The example provided in Shared does not work correctly when built with GCC using MinGW64 - the log output from the two shared libraries is never printed.

I've attempted to provide some instructions on how to reproduce, let me know if you have any issues.

Steps to Reproduce

If you don't have a MinGW environment;

  • Install MSYS2 from here: https://www.msys2.org/ if you don't have it installed
  • Launch a MINGW64 shell
  • Install relevant packages from pacman to get a build env if you don't have one
    • pacman -S mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja

Now build and run the sample

  • Clone Plog from master branch
  • Important: Edit the SharedApp/main.cpp to rename SharedLib1.dll and SharedLib2.dll in the LoadLibraryW calls to libSharedLib1.dll and libSharedLib2.dll (since cmake will prefix dll names with lib in this environment)
  • Build samples
$ mkdir build && cd build
$ cmake -DPLOG_BUILD_SAMPLES=1 ..
$ cmake --build .
  • Check shared app build as expected
$ ls samples/Shared/
cmake_install.cmake  CMakeFiles  libSharedApp.dll.a  libSharedLib1.dll  libSharedLib1.dll.a  libSharedLib2.dll  libSharedLib2.dll.a  SharedApp.exe
  • Run SharedApp.exe
$ ./SharedApp
  • Check the resulting log file
$ cat Shared.txt
2023-04-01 17:53:59.295 DEBUG [6804] [main@30] Hello from app!

The log messages from the two libraries is missing

Expected Behaviour

The shared libraries will import the Plog instance and print the expected log messages

Notes

Check the exported symbols from SharedApp.exe with Dependencies (https://github.com/lucasg/Dependencies), we can see SharedApp.exe does export the plog symbols:

2023-04-01 17_57_47-Dependencies (WoW64)

So the symbols are correctly being exported, but the shared libraries are not importing them correctly.

Calling plog::Logger<0>::getInstance(); in one of the shared libraries returns a null pointer.

Environment

  • MINGW64 installed with MSYS2
  • GCC 12.2 compiler
$ gcc --version
gcc.exe (Rev6, Built by MSYS2 project) 12.2.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  • CMake 3.25.1
  • Plog version d60df3a1efa99061f637c263fe4e467c273d8655
    • Same behaviour with last tagged release 1.1.9
@SergiusTheBest
Copy link
Owner

Your bug report is very good! I'll check this issue.

@SergiusTheBest SergiusTheBest self-assigned this Apr 5, 2023
@SergiusTheBest
Copy link
Owner

Unfortunately MinGW doesn't play well with exporting/importing classes and inline functions (and they should be inline as they are in headers). I don't see an easy way to fix this.

However you can achieve the similar functionality with the Chained example.

Related issues that have interesting details:

@TeknoVenus
Copy link
Author

Thanks for looking into this, really appreciate it.

Looks like the chained example will work fine for my needs, so can use that instead.

Might be worth adding a note in the readme that sharing the log instance across libs won't work properly in MinGW.

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

No branches or pull requests

2 participants