Hi Alex, Thansk for looking on this . In the last message, the compilation command is a bit misleading. I am filling in more details. If I keep "-Wl,-soname,$@" in the command , I got similar linking errors. makefile: SONAMES := $(addsuffix .dll,$(addprefix lib,$(NAMES)))
QEMU_CFLAGS += -fPIC -fno-stack-protector -DBUILDING_DLL QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu all: $(SONAMES) lib%.dll: %.o $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS) output: x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.dll -o libbb.dll bb.o C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.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/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `plugin_exit': C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:27: undefined reference to `g_strdup_printf' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:29: undefined reference to `qemu_plugin_outs' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `vcpu_tb_trans': C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:42: undefined reference to `qemu_plugin_tb_n_insns' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:45: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:47: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:50: undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `qemu_plugin_install': C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:64: undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:65: undefined reference to `qemu_plugin_register_atexit_cb' collect2.exe: error: ld returned 1 exit status On windows, I replace $LDLIBS with $LIBS here, because $LDLIBS seems undefined. But still yields linking error, except. lib%.dll: %.o $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LIBS)" x86_64-w64-mingw32-gcc -shared -Wl,-soname,libbb.dll -o libbb.dll 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/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `plugin_exit': C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:29: undefined reference to `qemu_plugin_outs' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `vcpu_tb_trans': C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:42: undefined reference to `qemu_plugin_tb_n_insns' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:45: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:47: undefined reference to `qemu_plugin_register_vcpu_tb_exec_inline' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:50: undefined reference to `qemu_plugin_register_vcpu_tb_exec_cb' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: bb.o: in function `qemu_plugin_install': C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:64: undefined reference to `qemu_plugin_register_vcpu_tb_trans_cb' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/QRS_Project/simdsp/qemu-4.2.0/tests/plugin/bb.c:65: undefined reference to `qemu_plugin_register_atexit_cb' The libdl library (where dlopen() is defined) was not shipped with MSYS2 mingw . It 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 ------------------------------------------- casmac <climber....@qq.com> writes: > Hi all, > I want to build QEMU 4.2.0 with the plugin module on > Windows 7 with Mingw, but the building process faild. I'm afraid I've never tried with mingw... that said: The step I follow is listed below: > 1. create "dsp_build" diretory under source file folder > > > 2. 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 > 3. build qemu project > 4. running "make -C tests/plugin", yeilds error: > CC bb.o > 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 > 17 | QEMU_PLUGIN_EXPORT int qemu_plugin_version = > QEMU_PLUGIN_VERSION; > | > ^~~~~~~~~~~~~~~~~~~ > 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] > > > 5. I modified the QEMU_CFLAGS and the compilation command > arguments($(CC) ..) in the makefile : > > > BUILD_DIR := $(CURDIR)/../.. > > > include $(BUILD_DIR)/config-host.mak > include $(SRC_PATH)/rules.mak > > > $(call set-vpath, $(SRC_PATH)/tests/plugin) > > > NAMES := > NAMES += bb > NAMES += empty > NAMES += insn > NAMES += mem > NAMES += hotblocks > NAMES += howvec > NAMES += hotpages > > > SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) > > > QEMU_CFLAGS += -fPIC -DBUILDING_DLL > #added -DBUILDING_DLL Looking at the definition: #if defined _WIN32 || defined __CYGWIN__ #ifdef BUILDING_DLL #define QEMU_PLUGIN_EXPORT __declspec(dllexport) #else #define QEMU_PLUGIN_EXPORT __declspec(dllimport) #endif #define QEMU_PLUGIN_LOCAL #else I expect BUILDING_DLL is for ensuring QEMU itself exports the plugin functions so the plugin can refer to them. So maybe try: ./configure --enable-plugins --extra-cflags="-DBUILDING_DLL" and remove the -DBUILDING_DLL from the plugins themselves? > QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu > > > all: $(SONAMES) > > > lib%.so: %.o > $(CC) -fPIC -shared -o $@ $^ $(LIBS) > # original command : $(CC) -shared -Wl,-soname,$@ -o $@ > $^ $(LDLIBS) > > > 6. Executing make yeilds: > > > make: enter > ??/d/emu_devl/qemu_src/qemu-sr-dsp-a/qemu_tidsp_c3x/build_dsp/tests/plugin?? > CC bb.o > x86_64-w64-mingw32-gcc -fPIC -shared -o libbb.so bb.o -L > /c/msys64/mingw64/lib/ -lglib-2.0 > 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' > collect2.exe: error: ld returned 1 exit status -- Alex Benn??e