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

Logging From Shared Libraries on Windows #83

Closed
dcc194 opened this issue Jan 8, 2016 · 3 comments
Closed

Logging From Shared Libraries on Windows #83

dcc194 opened this issue Jan 8, 2016 · 3 comments
Labels

Comments

@dcc194
Copy link

dcc194 commented Jan 8, 2016

I have a cross-platform (Linux & Windows) Qt Application that uses glog for logging (commit: 4d391fe). The project has a main application with several shared libraries that we wrote. On Linux (Ubuntu 14.04) glog works as expected. On Windows (built using mingw-w64 and gcc) any log statement that comes from within a DLL gets written to stdout instead of to the log. Any log statement from within the main application correctly gets written to the log. Furthermore, I see WARNING: Logging before InitGoogleLogging() is written to STDERR in the standard output for each time a log statement is created from a DLL for the first time (i.e. if I have 5 DLLs, I see that warning 5 times immediately prior to the first log statement from each DLL).

It seems like Glog is not being shared across the DLLs. I have tried to call InitGoogleLogging from within each DLL to test this theory, but then I get a run time crash with the following error message in stdout: Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!. So it appears that Glog is not being shared however, I can't initialize it in each DLL.

Full disclosure: I had to tweak port.h in order to get glog to build in mingw-w64 by handling pthreads correctly and not redefining localtime_r, but I don't feel this is related.

 #endif  // _MSC_VER

 // ----------------------------------- THREADS
+#ifndef PTHREAD_ONCE_INIT
 typedef DWORD pthread_t;
 typedef DWORD pthread_key_t;
 typedef LONG pthread_once_t;
 enum { PTHREAD_ONCE_INIT = 0 };   // important that this be 0! for SpinLock
 #define pthread_self  GetCurrentThreadId
 #define pthread_equal(pthread_t_1, pthread_t_2)  ((pthread_t_1)==(pthread_t_2))
+#endif

-inline struct tm* localtime_r(const time_t* timep, struct tm* result) {
-  localtime_s(result, timep);
-  return result;
-}
+//inline struct tm* localtime_r(const time_t* timep, struct tm* result) {
+//  localtime_s(result, timep);
+//  return result;
+//}
@wyl8899
Copy link

wyl8899 commented Feb 2, 2016

Also encountered the windows/port.h issue when trying to cross-compile.

Another issue to mention. The headers that are make installed still have the __declspec(dllimport) macro definitions, even when the build is configured to produce a static library. They cause "undefined reference to imp[some mangled symbol]" error when linking.

@davidalbertonogueira
Copy link

I have the same problem, but in Linux. How should someone approach these situations, in which a dynamic library uses Glog, and my client application also uses Glog? They cannot both call InitGoogleLogging. But the dynamic library cannot drop that Logging initialization call because it can be used in applications without Glog. Shouldn't exist something like InitGoogleSharedLogging?
Moreover, how to approach cases when the shared library and the main client use different versions of a library or one of them has Glog coupled with Gflags and the other not? How to make each one point to its "rightful" library?

@sergiud
Copy link
Collaborator

sergiud commented Feb 28, 2018

InitGoogleLogging should be ideally called only by the application that uses the libraries dependent on glog.

Closing the issue for now, since I cannot reproduce the problem.

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

4 participants