Problem with glib static build on Windows

I have Visual Studio 2019 Community edition and cmake installed.
I can build the default shared lib.

meson _build --backend=vs2019
cd _build
msbuild /m glib.sln

However, the static lib does not build.

meson _build --default-library static --backend=vs2019
cd _build
msbuild /m glib.sln

I also tried with

meson -Ddefault_library=static --backend=vs2019 _build
cd _build
msbuild /m glib.sln
ld\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         libgobject-2.0.a(gclosure.c.obj) : error LNK2001: unresolved external
       symbol __imp_ffi_type_sint32 [C:\Users\Administrator\Documents\glib\_bui
       ld\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         libgobject-2.0.a(gclosure.c.obj) : error LNK2001: unresolved external
       symbol __imp_ffi_type_uint64 [C:\Users\Administrator\Documents\glib\_bui
       ld\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         libgobject-2.0.a(gclosure.c.obj) : error LNK2001: unresolved external
       symbol __imp_ffi_type_sint64 [C:\Users\Administrator\Documents\glib\_bui
       ld\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         libgobject-2.0.a(gclosure.c.obj) : error LNK2001: unresolved external
       symbol __imp_ffi_type_float [C:\Users\Administrator\Documents\glib\_buil
       d\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         libgobject-2.0.a(gclosure.c.obj) : error LNK2001: unresolved external
       symbol __imp_ffi_type_double [C:\Users\Administrator\Documents\glib\_bui
       ld\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         libgobject-2.0.a(gclosure.c.obj) : error LNK2001: unresolved external
       symbol __imp_ffi_type_pointer [C:\Users\Administrator\Documents\glib\_bu
       ild\gio\tests\4076ad8@@appmonitor@exe.vcxproj]
         .\appmonitor.exe : fatal error LNK1120: 17 unresolved externals [C:\Us
       ers\Administrator\Documents\glib\_build\gio\tests\4076ad8@@appmonitor@ex
       e.vcxproj]

    340 Warning(s)
    3697 Error(s)

Building glib on windows statically is known to not work (with both the vs backend and the ninja backend): https://gitlab.gnome.org/GNOME/glib/-/issues/692

glib builds fine with the vs backend (and of course the ninja backend) if you don’t build statically, though. I just tested it.

I think the patch being used by conan/bincrafters in their static build is your own patch
0001-win32-Prefer-the-use-of-constructors-over-DllMain.patch

Is it possible for meson to use this patch for a current build ?

EDIT: I mean, is there a way I can pass some params to tell meson to use this patch during a build?

Yes, I wrote that patch 7 years ago, but it’s outdated now and does not apply to latest glib. Perhaps the version that Conan is carrying has been updated, in which case you can apply it with git am before you build it with meson :slight_smile: . Just make sure it’s the same version of glib that Conan is shipping.

However, build issues are another matter. I’m sure there are bugs since no one is testing it. You can try with --default-library=both which should generate both static libraries *.a and DLLs and use only the static libraries.

I hope that my comment will not be blocked as I’m going to post a link.

Conan definitely uses your patch -

0002-win32-Prefer-the-use-of-constructors-over-DllMain.patch

I’ll try to patch and report back later.

Nope. That patch fails with glib 2.64. I’ll try the Conan/bincrafters method and report later.

The patch does not work currently. However, SSE4 at conan has ported this sometime recently. I am leaving the link in here, in case someone want to follow it up.
If I get some guidance on the issue, I would be happy to make the changes to make static build work on glib.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.