hello Emilio,
  Thanks for looking at this issue. After adding  -DBUILDING_DLL to 
QEMU_CFLAGS, I still got linking error as follows, and it seems $LDLIB is empty:


x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.so -o libbb.so bb.o
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `g_autoptr_cleanup_generic_gfree':
C:/msys64/mingw64/include/glib-2.0/glib/glib-autocleanups.h:28: undefined 
reference to `g_free'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `plugin_exit':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:26: 
undefined reference to `g_strdup_printf'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:28: 
undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:29: 
undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `vcpu_tb_trans':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:41: 
undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:44: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:46: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:49: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `qemu_plugin_install':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:63: 
undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:64: 
undefined reference to `qemu_plugin_register_atexit_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o:bb.c:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): 
undefined reference to `__stack_chk_guard'
collect2.exe: error: ld returned 1 exit status
   
   If I replace $LDLIBS with $LIBS, linking error to glib functions 
disappeared , and other error remains:


x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.so -o libbb.so bb.o -ldl 
-LC:/msys64/mingw64/lib -lz -LC:/msys64/mingw64/lib -lgmodule-2.0 -pthread 
-lglib-2.0 -lintl -LC:/msys64/mingw64/lib -lgthread-2.0 -pthread -lglib-2.0 
-lintl -lwinmm -lws2_32 -liphlpapi
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `plugin_exit':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:28: 
undefined reference to `qemu_plugin_outs'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:29: 
undefined reference to `__stack_chk_fail'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `vcpu_tb_trans':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:41: 
undefined reference to `qemu_plugin_tb_n_insns'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:44: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:46: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:49: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `qemu_plugin_install':
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:63: 
undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:64: 
undefined reference to `qemu_plugin_register_atexit_cb'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o:bb.c:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): 
undefined reference to `__stack_chk_guard'
collect2.exe: error: ld returned 1 exit status

  The libdl library (where dlopen() is defined) is compiled from 
source(https://github.com/dlfcn-win32/dlfcn-win32), and I place the generated 
libdl.dll, libdl.a, libdl.dll.a in C:\msys64\mingw64\include.  dlfcn.h in 
C:\msys64\mingw64\include.  


regards,
xiaolei





------------------ ???????? ------------------
:&nbsp;"Emilio G. Cota"<1885...@bugs.launchpad.net&gt;;
:&nbsp;2020??7??4??(??????) ????11:16:&nbsp;"casmac"<1482995...@qq.com&gt;;


:&nbsp;[Bug 1885827] Re: building plugin failed on Windows with mingw



I never built the plugin code on anything other than Linux :(
All I did for Windows is to try to follow https://gcc.gnu.org/wiki/Visibility

Can you please try the following patch (with no other changes)?
The patch applies on top of v4.2.0.

diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile
index 75467b6db8..5b3611ad63 100644
--- a/tests/plugin/Makefile
+++ b/tests/plugin/Makefile
@@ -16,7 +16,7 @@ NAMES += hotpages

&nbsp;SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))

-QEMU_CFLAGS += -fPIC
+QEMU_CFLAGS += -fPIC -DBUILDING_DLL
&nbsp;QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu

&nbsp;all: $(SONAMES)

-- 
You received this bug notification because you are subscribed to the bug
report.
https://bugs.launchpad.net/bugs/1885827

Title:
&nbsp; building plugin failed on Windows with mingw

Status in QEMU:
&nbsp; New

Bug description:
&nbsp; I want to build QEMU 4.2.0's plugin module on Windows 7/10 with Mingw, 
but the building process faild.
&nbsp;&nbsp; 
&nbsp; The step I follow is listed below:
&nbsp; 1. create "dsp_build" diretory under source file folder

&nbsp; 2.&nbsp; change directory to dsp_build , and run ../configure 
--target-list=dsp-softmmu --cross-prefix=x86_64-w64-mingw32- --enable-gtk 
--enable-sdl --enable-debug --enable-plugins
&nbsp; 3. build qemu project
&nbsp; 4. switch dir to /dsp_build, make -C tests/plugin, yeilds error: 
&nbsp;&nbsp; &nbsp; CC&nbsp;&nbsp;&nbsp; &nbsp; bb.o
&nbsp;&nbsp; 
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:17:24: 
error: variable 'qemu_plugin_version' definition is marked dllimport
&nbsp;&nbsp; &nbsp; 17 | QEMU_PLUGIN_EXPORT int qemu_plugin_version = 
QEMU_PLUGIN_VERSION;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; ^~~~~~~~~~~~~~~~~~~
&nbsp;&nbsp; 
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:17:24: 
warning: 'qemu_plugin_version' redeclared without dllimport attribute: previous 
dllimport ignored [-Wattributes]
&nbsp;&nbsp; 
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c: In 
function 'vcpu_tb_exec':
&nbsp;&nbsp; 
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:33:29: 
warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
&nbsp;&nbsp; &nbsp; 33 |&nbsp;&nbsp; &nbsp; unsigned long n_insns = (unsigned 
long)udata;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; ^
&nbsp;&nbsp; 
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c: In 
function 'vcpu_tb_trans':
&nbsp;&nbsp; 
D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:51:46: 
warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
&nbsp;&nbsp; &nbsp; 51 
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; (void *)n_insns);

&nbsp; 5.&nbsp; Then , I modified the QEMU_flags and the compilation command
&nbsp; arguments($(CC) ..) in&nbsp; the&nbsp; makefile :

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; BUILD_DIR := $(CURDIR)/../..

&nbsp;          include $(BUILD_DIR)/config-host.mak
&nbsp;          include $(SRC_PATH)/rules.mak

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; $(call set-vpath, $(SRC_PATH)/tests/plugin)

&nbsp;          NAMES :=
&nbsp;          NAMES += bb
&nbsp;          NAMES += empty
&nbsp;          NAMES += insn
&nbsp;          NAMES += mem
&nbsp;          NAMES += hotblocks
&nbsp;          NAMES += howvec
&nbsp;          NAMES += hotpages

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))

&nbsp;          QEMU_CFLAGS += -fPIC    -DBUILDING_DLL&nbsp;            
#added&nbsp; -DBUILDING_DLL
&nbsp;          QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; all: $(SONAMES)

&nbsp;          lib%.so: %.o
&nbsp;                  $(CC) -fPIC -shared -o $@ $^ $(LDLIBS) -L 
/c/msys64/mingw64/lib/ -lglib-2.0
&nbsp;                  # original cmd: $(CC) -shared -Wl,-soname,$@ -o $@ $^ 
$(LDLIBS)

&nbsp;          clean:
&nbsp;                  rm -f *.o *.so *.d
&nbsp;                  rm -Rf .libs

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 &nbsp; .PHONY: all clean

&nbsp; 6.&nbsp; Executing make yeilds:

&nbsp; make: enter &nbsp; 
??/d/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/build_dsp/tests/plugin??
&nbsp; &nbsp; CC&nbsp;&nbsp;&nbsp; &nbsp; bb.o
&nbsp; x86_64-w64-mingw32-gcc -fPIC -shared -o libbb.so bb.o&nbsp; -L 
/c/msys64/mingw64/lib/ -lglib-2.0
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `plugin_exit':
&nbsp; D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:28: 
undefined reference to `qemu_plugin_outs'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:29: 
undefined reference to `__stack_chk_fail'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `vcpu_tb_trans':
&nbsp; D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:41: 
undefined reference to `qemu_plugin_tb_n_insns'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:44: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:46: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:49: 
undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o: in function `qemu_plugin_install':
&nbsp; D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:63: 
undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 D:/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/tests/plugin/bb.c:64: 
undefined reference to `qemu_plugin_register_atexit_cb'
&nbsp; 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
 bb.o:bb.c:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): 
undefined reference to `__stack_chk_guard'
&nbsp; collect2.exe: error: ld returned 1 exit status

&nbsp;&nbsp; &nbsp; It looks like linking problem(fail to link functions 
defined in api.c, core.c...), but I have no idea what goes wrong. If I mannualy 
add api.o, core.o in the compilation command, still get error like undefined 
reference to '__stack_chk_guard'. 
&nbsp;&nbsp; &nbsp; My collegue can build 4.2.0&nbsp; plugins on Ubuntu Linux 
without any problem.

To manage notifications about this bug go to:
https://bugs.launchpad.net/qemu/+bug/1885827/+subscriptions

Reply via email to