Re: Questions about mingw static libraries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, May 05, 2023 at 09:31:02PM -0600, Orion Poplawski wrote:
> I'm just starting to look into the mingw packages and building mingw
> executables with them - and in particular static building.  I'm
> hoping someone can clarify some things for me.
> 
> For "regular" libs we seem to have:
> 
> %{mingw32_bindir}/libexample-0.dll
> %{mingw32_libdir}/libexample.dll.a
> 
> and for static libs:
> 
> %{mingw32_libdir}/libexample.a

I see you've already concluded this is a problem in the build system,
but just to clarify a few things ...

[...]
> From what I've gleaned from some web searches is that the .dll.a
> file is an "import" library which seems to encode a dependency on
> the .dll library at runtime, while the plain .a file is a more
> "normal" static library.

Correct -- *.dll.a is part of how Windows binaries use dynamic libraries.

Apparently their link loader isn't able to just consume a *.dll
directly, in the way that ELF can just use a *.so.  Instead all
binaries needs a stub of code to be linked into them (the *.dll.a
thing) which contains calls to Win32 functions like LoadLibrary that
locates and loads the dll at runtime.  On Windows this stub is called
an import library (or sometimes "implib") and has the extension *.lib.

https://en.wikipedia.org/wiki/Dynamic-link_library#Import_libraries

> So to link a static executable it looks like I want to be using
> libQt5Gui.a.  However, when attempting to build the x2goclient
> executable I'm ending up with the following link line:
> 
> i686-w64-mingw32-g++ -g -fstack-protector -static -static-libstdc++
> -static-libgcc -Wl,-subsystem,windows -mthreads -o
> release/x2goclient.exe @object_script.x2goclient.Release  -lssh.dll
> -lwinspool /usr/i686-w64-mingw32/sys-root/mingw/lib/libQt5Svg.dll.a
> /usr/i686-w64-mingw32/sys-root/mingw/lib/libQt5Widgets.dll.a
> /usr/i686-w64-mingw32/sys-root/mingw/lib/libQt5Gui.dll.a -lgdi32
> -lcomdlg32 -loleaut32 -limm32 -luxtheme -ljpeg -lpng -lharfbuzz
> /usr/i686-w64-mingw32/sys-root/mingw/lib/libQt5Network.dll.a
> -lcrypt32 -ldnsapi -liphlpapi
> /usr/i686-w64-mingw32/sys-root/mingw/lib/libQt5Core.dll.a -lz
> -lpcre2-16 -lversion -lole32 -luuid -lwinmm -lws2_32 -ladvapi32
> -lshell32 -luser32 -lkernel32 -lnetapi32 -luserenv -liconv
> release/x2goclient_res.o -lmingw32
> /usr/i686-w64-mingw32/sys-root/mingw/lib/libqt5main.a -lshell32
> 
> with lots of references to the .dll.a files.  And from what I can
> tell, the x2goclient.exe executable does appear to have runtime
> dependencies on the various Qt dlls (e.g. Qt5Gui.dll, etc.).

As you concluded already, this link command looks very wrong.  The use
of -static with implibs shows some confusion in the build system.

FWIW zlib is a simpler package that we know works:

$ rpm -ql mingw64-zlib
/usr/x86_64-w64-mingw32/sys-root/mingw/bin/zlib1.dll     <- DLL
/usr/x86_64-w64-mingw32/sys-root/mingw/include/zconf.h
/usr/x86_64-w64-mingw32/sys-root/mingw/include/zlib.h
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.dll.a    <- implib
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/pkgconfig/zlib.pc

$ rpm -ql mingw64-zlib-static
/usr/x86_64-w64-mingw32/sys-root/mingw/lib/libz.a        <- static lib

$ cat test-inflate.c 
#include <zlib.h>
z_stream z;
int main () { inflateInit (&z); return 0; }

$ x86_64-w64-mingw32-gcc test-inflate.c -lz 
$ strings a.exe | fgrep '.dll'
KERNEL32.dll
msvcrt.dll
zlib1.dll

$ x86_64-w64-mingw32-gcc test-inflate.c -lz -static
$ strings a.exe | fgrep '.dll'
KERNEL32.dll
msvcrt.dll

(I wish we had better analysis tools for PE files!)

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
_______________________________________________
devel mailing list -- devel@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/devel@xxxxxxxxxxxxxxxxxxxxxxx
Do not reply to spam, report it: https://pagure.io/fedora-infrastructure/new_issue




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Fedora Announce]     [Fedora Users]     [Fedora Kernel]     [Fedora Testing]     [Fedora Formulas]     [Fedora PHP Devel]     [Kernel Development]     [Fedora Legacy]     [Fedora Maintainers]     [Fedora Desktop]     [PAM]     [Red Hat Development]     [Gimp]     [Yosemite News]

  Powered by Linux