diff mbox series

[Bug,1885827] Re: building plugin failed on Windows with mingw

Message ID 159390787028.1458.9877661384077260896.malone@wampee.canonical.com
State New
Headers show
Series [Bug,1885827] Re: building plugin failed on Windows with mingw | expand

Commit Message

Emilio G. Cota July 5, 2020, 12:11 a.m. UTC
Xiaolei confirmed to me via email that adding -DBUILDING_DLL is not
enough to fix the problem.

I looked into this a bit further and it looks like we need an "import library" to be created when compiling the QEMU binary. This is accomplished by adding "-Wl,--out-implib,libqemu_plugin.a" to the linker invocation to build the QEMU binary. See these two stackoverflow questions:
- https://stackoverflow.com/questions/17601949/building-a-shared-library-using-gcc-on-linux-and-mingw-on-windows
- https://stackoverflow.com/questions/39759060/compile-to-dll-with-some-undefined-references-with-mingw

It's not clear to me whether any import library with the symbols needed
can work, or whether each target binary needs its corresponding import
library, e.g. aarch64-linux-user and x86_64-linux-user need different
libraries. The below is an attempt at the latter approach; one would
just have to link the appropriate import library with "-l" when building
the plugin.

Please give this a try, and don't forget to also pass -DBUILDING_DLL to
the linker.
diff mbox series


diff --git a/Makefile b/Makefile
index b437a346d7..5cc1bc8e23 100644
--- a/Makefile
+++ b/Makefile
@@ -866,8 +866,14 @@  ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512
        $(INSTALL_DIR) "$(DESTDIR)$(includedir)"
+       $(INSTALL_DIR) "$(DESTDIR)$(libdir)"
+       for d in $(TARGET_DIRS); do \
+               $(INSTALL_DIR) "$(DESTDIR)$(libdir)/$$d"; \
+       done
 install: all $(if $(BUILD_DOCS),install-doc) \
-       install-datadir install-localstatedir install-includedir \
+       install-datadir install-localstatedir install-includedir install-libdir \
        $(if $(INSTALL_BLOBS),$(edk2-decompressed)) \
 ifneq ($(TOOLS),)
@@ -932,6 +938,11 @@  ifdef CONFIG_GTK
 ifeq ($(CONFIG_PLUGIN),y)
        $(INSTALL_DATA) $(SRC_PATH)/include/qemu/qemu-plugin.h "$(DESTDIR)$(includedir)/qemu-plugin.h"
+# ifeq MINGW, WINDOWS or similar.
+       for d in $(TARGET_DIRS); do \
+               $(INSTALL_DATA) "$$d/libqemu_plugin.dll.a" "$(DESTDIR)$(libdir)/$$d/libqemu_plugin.dll.a"; \
+       done
+# endif
        $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps"
        set -e; for x in $(KEYMAPS); do \
diff --git a/configure b/configure
index 6099be1d84..9606f6e888 100755
--- a/configure
+++ b/configure
@@ -7455,6 +7455,9 @@  if test "$plugins" = "yes" ; then
            "If \$plugins=yes, either \$ld_dynamic_list or " \
            "\$ld_exported_symbols_list should have been set to 'yes'."
+    # if test "$mingw32" = "yes" ; then # or mingw, or windows; I don't know.
+       QEMU_LDFLAGS="-Wl,--out-implib,libqemu_plugin.dll.a"
+    # fi
 if test "$tcg_interpreter" = "yes"; then