GNOME Bugzilla – Bug 678387
No initialisation when using static version of glib under win32
Last modified: 2012-10-09 15:44:18 UTC
Created attachment 216730 [details] [review] Proposed fix, but with a TODO (so not to be merged as-is, probably). When a statically linked version of the library is used (under mingw32), the clock/thread init functions aren't called - this results in segfaults in various windows functions (and of course the app doesn't work). This seems to be a result of the rework around the commit 47444dacc069be5984df4064ae382d45a9ae8c9e . The reason seems to be that while DllMain() does call e.g. g_thread_win32_init(), the glib_init_ctor() doesn't. Also, glib_init_ctor() doesn't seem to be used when a static version of the lib is compiled for win32.
Review of attachment 216730 [details] [review]: I can confirm this is an issue with a static glib on win32 relative to glib-2.30. ::: glib-2.32.2.orig/glib/glib-init.c @@ +225,3 @@ HMODULE glib_dll; +#if defined (G_OS_WIN32) && SHARED_BUILD I think you need to keep the G_OS_WIN32 conditional around glib_dll otherwise it will be declared for all platforms, which is not what we want. Also, I think the proper thing to use here is GLIB_STATIC_COMPILATION since that's what's defined when --enable-static is passed to the build on win32. Here's what I came up with that's working: @@ -225,6 +225,10 @@ glib_init (void) HMODULE glib_dll; +#endif + +#if defined (G_OS_WIN32) && !defined (GLIB_STATIC_COMPILATION) + BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, @@ +266,3 @@ + * static-linked app? + * glib_dll = GetModuleHandle(NULL); + */ I don't think it's necessary to set glib_dll here. It will be initialized to NULL above. It will then be passed to GetModuleHandleW in gutils.c:_glib_get_dll_directory. See the comment there about what happens with a static glib. @@ +268,3 @@ + */ + g_clock_win32_init (); + g_thread_win32_init (); I think these guys need to be wrapped in G_OS_WIN32 so they're not called on other platforms.
Created attachment 221665 [details] [review] glib-init: Fully initialize from constructor when built static on win32 Here's an updated patch keeping Andrej as the author. This is working for me when I build static for linux or windows (I'm embedding glib in pkg-config).
This is bug #660731. As I mention there this is trickier than it seems because we depend on using DllMain() in the case of thread attach/detach. I lean toward saying we should not support static compiles of glib... *** This bug has been marked as a duplicate of bug 660731 ***