[Libguestfs] [PATCH nbdkit 2/9] build: On Windows only, link all plugins and filters with -lnbdkit.

Richard W.M. Jones
2020-08-18T10:50:06Z

---
 configure.ac                     |  2 ++
 filters/blocksize/Makefile.am    |  1 +
 filters/cache/Makefile.am        |  1 +
 filters/cacheextents/Makefile.am |  1 +
 filters/cow/Makefile.am          |  1 +
 filters/ddrescue/Makefile.am     |  1 +
 filters/delay/Makefile.am        |  3 +++
 filters/error/Makefile.am        |  1 +
 filters/exitlast/Makefile.am     |  3 +++
 filters/ext2/Makefile.am         |  3 ++-
 filters/extentlist/Makefile.am   |  1 +
 filters/fua/Makefile.am          |  3 +++
 filters/gzip/Makefile.am         |  1 +
 filters/ip/Makefile.am           |  1 +
 filters/limit/Makefile.am        |  1 +
 filters/log/Makefile.am          |  1 +
 filters/nocache/Makefile.am      |  3 +++
 filters/noextents/Makefile.am    |  3 +++
 filters/nofilter/Makefile.am     |  3 +++
 filters/noparallel/Makefile.am   |  3 +++
 filters/nozero/Makefile.am       |  3 +++
 filters/offset/Makefile.am       |  1 +
 filters/partition/Makefile.am    |  1 +
 filters/pause/Makefile.am        |  1 +
 filters/rate/Makefile.am         |  1 +
 filters/readahead/Makefile.am    |  1 +
 filters/retry/Makefile.am        |  1 +
 filters/stats/Makefile.am        |  1 +
 filters/swab/Makefile.am         |  1 +
 filters/tar/Makefile.am          |  1 +
 filters/tls-fallback/Makefile.am |  3 +++
 filters/truncate/Makefile.am     |  1 +
 filters/xz/Makefile.am           |  1 +
 plugins/cc/Makefile.am           |  1 +
 plugins/cdi/Makefile.am          |  1 +
 plugins/curl/Makefile.am         |  3 ++-
 plugins/data/Makefile.am         |  1 +
 plugins/eval/Makefile.am         |  1 +
 plugins/example1/Makefile.am     |  3 +++
 plugins/example2/Makefile.am     |  3 +++
 plugins/example3/Makefile.am     |  3 +++
 plugins/file/Makefile.am         |  1 +
 plugins/floppy/Makefile.am       |  1 +
 plugins/full/Makefile.am         |  3 +++
 plugins/guestfs/Makefile.am      |  3 ++-
 plugins/gzip/Makefile.am         |  1 +
 plugins/info/Makefile.am         |  1 +
 plugins/iso/Makefile.am          |  1 +
 plugins/libvirt/Makefile.am      |  1 +
 plugins/linuxdisk/Makefile.am    |  1 +
 plugins/lua/Makefile.am          |  3 +++
 plugins/memory/Makefile.am       |  1 +
 plugins/nbd/Makefile.am          |  1 +
 plugins/null/Makefile.am         |  3 +++
 plugins/ondemand/Makefile.am     |  1 +
 plugins/partitioning/Makefile.am |  1 +
 plugins/pattern/Makefile.am      |  3 +++
 plugins/perl/Makefile.am         |  1 +
 plugins/python/Makefile.am       |  3 ++-
 plugins/random/Makefile.am       |  3 +++
 plugins/ruby/Makefile.am         |  1 +
 plugins/sh/Makefile.am           |  1 +
 plugins/split/Makefile.am        |  1 +
 plugins/ssh/Makefile.am          |  3 ++-
 plugins/streaming/Makefile.am    |  3 +++
 plugins/tar/Makefile.am          |  7 ++++---
 plugins/tcl/Makefile.am          |  5 ++++-
 plugins/tmpdisk/Makefile.am      |  7 ++++---
 plugins/torrent/Makefile.am      | 11 ++++++-----
 plugins/vddk/Makefile.am         |  1 +
 plugins/zero/Makefile.am         |  3 +++
 tests/Makefile.am                | 10 ++++++++++
 72 files changed, 139 insertions(+), 17 deletions(-)

diff --git a/configure.ac b/configure.ac
index 84e50e72..1ac0eab7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -457,11 +457,13 @@ AS_CASE([$host_os],
     [mingw*|msys*|cygwin*], [
         is_windows=yes
         NO_UNDEFINED_ON_WINDOWS="-no-undefined"
+        LINK_LIBNBDKIT_ON_WINDOWS='$(top_builddir)/server/libnbdkit.la'
     ],
     [is_windows=no]
 )
 AC_MSG_RESULT([$is_windows])
 AC_SUBST([NO_UNDEFINED_ON_WINDOWS])
+AC_SUBST([LINK_LIBNBDKIT_ON_WINDOWS])

 AC_SEARCH_LIBS([getaddrinfo], [network socket])

diff --git a/filters/blocksize/Makefile.am b/filters/blocksize/Makefile.am
index ea51246a..dcb9352c 100644
--- a/filters/blocksize/Makefile.am
+++ b/filters/blocksize/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_blocksize_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_blocksize_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/cache/Makefile.am b/filters/cache/Makefile.am
index 200cda15..a98be192 100644
--- a/filters/cache/Makefile.am
+++ b/filters/cache/Makefile.am
@@ -61,6 +61,7 @@ nbdkit_cache_filter_la_LDFLAGS = \
 nbdkit_cache_filter_la_LIBADD = \
 	$(top_builddir)/common/bitmap/libbitmap.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/cacheextents/Makefile.am b/filters/cacheextents/Makefile.am
index 2f7a689b..8dfc067e 100644
--- a/filters/cacheextents/Makefile.am
+++ b/filters/cacheextents/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_cacheextents_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_cacheextents_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/cow/Makefile.am b/filters/cow/Makefile.am
index 4ff08a44..02e2c504 100644
--- a/filters/cow/Makefile.am
+++ b/filters/cow/Makefile.am
@@ -56,6 +56,7 @@ nbdkit_cow_filter_la_LDFLAGS = \
 nbdkit_cow_filter_la_LIBADD = \
 	$(top_builddir)/common/bitmap/libbitmap.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/ddrescue/Makefile.am b/filters/ddrescue/Makefile.am
index 79bbad9c..f8aeecfe 100644
--- a/filters/ddrescue/Makefile.am
+++ b/filters/ddrescue/Makefile.am
@@ -57,6 +57,7 @@ nbdkit_ddrescue_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_ddrescue_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(GNUTLS_LIBS) \
 	$(NULL)

diff --git a/filters/delay/Makefile.am b/filters/delay/Makefile.am
index 470c6062..e7b097eb 100644
--- a/filters/delay/Makefile.am
+++ b/filters/delay/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_delay_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_delay_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_delay_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_delay_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/error/Makefile.am b/filters/error/Makefile.am
index 78e2a7b7..c638085b 100644
--- a/filters/error/Makefile.am
+++ b/filters/error/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_error_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_error_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/exitlast/Makefile.am b/filters/exitlast/Makefile.am
index 17603951..71596799 100644
--- a/filters/exitlast/Makefile.am
+++ b/filters/exitlast/Makefile.am
@@ -42,6 +42,9 @@ nbdkit_exitlast_filter_la_SOURCES = \

 nbdkit_exitlast_filter_la_CPPFLAGS = -I$(top_srcdir)/include
 nbdkit_exitlast_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_exitlast_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_exitlast_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/ext2/Makefile.am b/filters/ext2/Makefile.am
index b1fdcb8c..5eb53562 100644
--- a/filters/ext2/Makefile.am
+++ b/filters/ext2/Makefile.am
@@ -53,8 +53,9 @@ nbdkit_ext2_filter_la_CFLAGS = \
 	$(EXT2FS_CFLAGS) $(COM_ERR_CFLAGS) \
 	$(NULL)
 nbdkit_ext2_filter_la_LIBADD = \
-	$(EXT2FS_LIBS) $(COM_ERR_LIBS) \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(EXT2FS_LIBS) $(COM_ERR_LIBS) \
 	$(NULL)
 nbdkit_ext2_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/filters/extentlist/Makefile.am b/filters/extentlist/Makefile.am
index 612fdfc8..975cb07f 100644
--- a/filters/extentlist/Makefile.am
+++ b/filters/extentlist/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_extentlist_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_extentlist_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/fua/Makefile.am b/filters/fua/Makefile.am
index 9fd056df..7ba329b2 100644
--- a/filters/fua/Makefile.am
+++ b/filters/fua/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_fua_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_fua_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_fua_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_fua_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/gzip/Makefile.am b/filters/gzip/Makefile.am
index d122c032..88c4041e 100644
--- a/filters/gzip/Makefile.am
+++ b/filters/gzip/Makefile.am
@@ -53,6 +53,7 @@ nbdkit_gzip_filter_la_CFLAGS = \
 	$(NULL)
 nbdkit_gzip_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(ZLIB_LIBS) \
 	$(NULL)
 nbdkit_gzip_filter_la_LDFLAGS = \
diff --git a/filters/ip/Makefile.am b/filters/ip/Makefile.am
index 16d23057..cf990a86 100644
--- a/filters/ip/Makefile.am
+++ b/filters/ip/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_ip_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_ip_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/limit/Makefile.am b/filters/limit/Makefile.am
index c721700c..0b9b6f2d 100644
--- a/filters/limit/Makefile.am
+++ b/filters/limit/Makefile.am
@@ -51,6 +51,7 @@ nbdkit_limit_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_limit_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/log/Makefile.am b/filters/log/Makefile.am
index f2c4d813..e7670434 100644
--- a/filters/log/Makefile.am
+++ b/filters/log/Makefile.am
@@ -51,6 +51,7 @@ nbdkit_log_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_log_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/nocache/Makefile.am b/filters/nocache/Makefile.am
index c3cb35f7..8f9022bb 100644
--- a/filters/nocache/Makefile.am
+++ b/filters/nocache/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_nocache_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/include \
 	$(NULL)
 nbdkit_nocache_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_nocache_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_nocache_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/noextents/Makefile.am b/filters/noextents/Makefile.am
index 81e826e9..5adcb2cc 100644
--- a/filters/noextents/Makefile.am
+++ b/filters/noextents/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_noextents_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_noextents_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_noextents_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_noextents_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/nofilter/Makefile.am b/filters/nofilter/Makefile.am
index 77ebe33d..a338efce 100644
--- a/filters/nofilter/Makefile.am
+++ b/filters/nofilter/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_nofilter_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/include \
 	$(NULL)
 nbdkit_nofilter_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_nofilter_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_nofilter_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/noparallel/Makefile.am b/filters/noparallel/Makefile.am
index fc5a5522..22322dd6 100644
--- a/filters/noparallel/Makefile.am
+++ b/filters/noparallel/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_noparallel_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/include \
 	$(NULL)
 nbdkit_noparallel_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_noparallel_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_noparallel_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/nozero/Makefile.am b/filters/nozero/Makefile.am
index ab7abf44..3611368c 100644
--- a/filters/nozero/Makefile.am
+++ b/filters/nozero/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_nozero_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/include \
 	$(NULL)
 nbdkit_nozero_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_nozero_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_nozero_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/offset/Makefile.am b/filters/offset/Makefile.am
index a579b8ce..708276fb 100644
--- a/filters/offset/Makefile.am
+++ b/filters/offset/Makefile.am
@@ -51,6 +51,7 @@ nbdkit_offset_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_offset_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/partition/Makefile.am b/filters/partition/Makefile.am
index 49e3e213..4fb70c7a 100644
--- a/filters/partition/Makefile.am
+++ b/filters/partition/Makefile.am
@@ -56,6 +56,7 @@ nbdkit_partition_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_partition_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/pause/Makefile.am b/filters/pause/Makefile.am
index 3f83eb03..d60bbe7d 100644
--- a/filters/pause/Makefile.am
+++ b/filters/pause/Makefile.am
@@ -48,6 +48,7 @@ nbdkit_pause_filter_la_CPPFLAGS = \
 nbdkit_pause_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
 nbdkit_pause_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_pause_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/filters/rate/Makefile.am b/filters/rate/Makefile.am
index 7f61ca44..bf96c4d2 100644
--- a/filters/rate/Makefile.am
+++ b/filters/rate/Makefile.am
@@ -50,6 +50,7 @@ nbdkit_rate_filter_la_CPPFLAGS = \
 nbdkit_rate_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
 nbdkit_rate_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_rate_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/filters/readahead/Makefile.am b/filters/readahead/Makefile.am
index 387750c2..a2c00624 100644
--- a/filters/readahead/Makefile.am
+++ b/filters/readahead/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_readahead_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_readahead_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/retry/Makefile.am b/filters/retry/Makefile.am
index 1011bff8..0d783dad 100644
--- a/filters/retry/Makefile.am
+++ b/filters/retry/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_retry_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_retry_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/stats/Makefile.am b/filters/stats/Makefile.am
index be06a08d..a0c1275d 100644
--- a/filters/stats/Makefile.am
+++ b/filters/stats/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_stats_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_stats_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/swab/Makefile.am b/filters/swab/Makefile.am
index 7acaa6a6..26d40403 100644
--- a/filters/swab/Makefile.am
+++ b/filters/swab/Makefile.am
@@ -57,6 +57,7 @@ nbdkit_swab_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_swab_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(GNUTLS_LIBS) \
 	$(NULL)

diff --git a/filters/tar/Makefile.am b/filters/tar/Makefile.am
index 30e973cc..9c67d0d9 100644
--- a/filters/tar/Makefile.am
+++ b/filters/tar/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_tar_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_tar_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/tls-fallback/Makefile.am b/filters/tls-fallback/Makefile.am
index 516c2ccf..0cd5bd1b 100644
--- a/filters/tls-fallback/Makefile.am
+++ b/filters/tls-fallback/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_tls_fallback_filter_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/include \
 	$(NULL)
 nbdkit_tls_fallback_filter_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_tls_fallback_filter_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_tls_fallback_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/filters/filters.syms \
diff --git a/filters/truncate/Makefile.am b/filters/truncate/Makefile.am
index 3b3d6aca..ddbdb052 100644
--- a/filters/truncate/Makefile.am
+++ b/filters/truncate/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_truncate_filter_la_LDFLAGS = \
 	$(NULL)
 nbdkit_truncate_filter_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/filters/xz/Makefile.am b/filters/xz/Makefile.am
index 63bbd1c5..8712d2d8 100644
--- a/filters/xz/Makefile.am
+++ b/filters/xz/Makefile.am
@@ -57,6 +57,7 @@ nbdkit_xz_filter_la_CFLAGS = \
 nbdkit_xz_filter_la_LIBADD = \
 	$(LIBLZMA_LIBS) \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_xz_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/cc/Makefile.am b/plugins/cc/Makefile.am
index 82db7200..947b92e4 100644
--- a/plugins/cc/Makefile.am
+++ b/plugins/cc/Makefile.am
@@ -54,6 +54,7 @@ nbdkit_cc_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_cc_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(DL_LIBS) \
 	$(NULL)

diff --git a/plugins/cdi/Makefile.am b/plugins/cdi/Makefile.am
index 9ce98d5f..1c2904d8 100644
--- a/plugins/cdi/Makefile.am
+++ b/plugins/cdi/Makefile.am
@@ -55,6 +55,7 @@ nbdkit_cdi_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_cdi_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(JANSSON_LIBS) \
 	$(NULL)

diff --git a/plugins/curl/Makefile.am b/plugins/curl/Makefile.am
index 29183f03..175f034e 100644
--- a/plugins/curl/Makefile.am
+++ b/plugins/curl/Makefile.am
@@ -54,8 +54,9 @@ nbdkit_curl_plugin_la_CFLAGS = \
 	$(CURL_CFLAGS) \
 	$(NULL)
 nbdkit_curl_plugin_la_LIBADD = \
-	$(CURL_LIBS) \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(CURL_LIBS) \
 	$(NULL)
 nbdkit_curl_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/data/Makefile.am b/plugins/data/Makefile.am
index de6e80bb..f4684915 100644
--- a/plugins/data/Makefile.am
+++ b/plugins/data/Makefile.am
@@ -62,6 +62,7 @@ nbdkit_data_plugin_la_LDFLAGS = \
 nbdkit_data_plugin_la_LIBADD = \
 	$(top_builddir)/common/allocators/liballocators.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(GNUTLS_LIBS) \
 	$(NULL)

diff --git a/plugins/eval/Makefile.am b/plugins/eval/Makefile.am
index 4ea8d7d4..4b2aa598 100644
--- a/plugins/eval/Makefile.am
+++ b/plugins/eval/Makefile.am
@@ -65,6 +65,7 @@ nbdkit_eval_plugin_la_CPPFLAGS = \
 nbdkit_eval_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 nbdkit_eval_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_eval_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/example1/Makefile.am b/plugins/example1/Makefile.am
index 450b367f..12aca60d 100644
--- a/plugins/example1/Makefile.am
+++ b/plugins/example1/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_example1_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_example1_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_example1_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_example1_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/example2/Makefile.am b/plugins/example2/Makefile.am
index 41fe1378..d78ab386 100644
--- a/plugins/example2/Makefile.am
+++ b/plugins/example2/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_example2_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_example2_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_example2_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_example2_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/example3/Makefile.am b/plugins/example3/Makefile.am
index e721896e..756c0d2f 100644
--- a/plugins/example3/Makefile.am
+++ b/plugins/example3/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_example3_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_example3_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_example3_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_example3_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/file/Makefile.am b/plugins/file/Makefile.am
index ae72a9c4..30999a52 100644
--- a/plugins/file/Makefile.am
+++ b/plugins/file/Makefile.am
@@ -52,6 +52,7 @@ nbdkit_file_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_file_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/floppy/Makefile.am b/plugins/floppy/Makefile.am
index 33d026fa..6636caf2 100644
--- a/plugins/floppy/Makefile.am
+++ b/plugins/floppy/Makefile.am
@@ -60,6 +60,7 @@ nbdkit_floppy_plugin_la_LDFLAGS = \
 nbdkit_floppy_plugin_la_LIBADD = \
 	$(top_builddir)/common/regions/libregions.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/full/Makefile.am b/plugins/full/Makefile.am
index 97101d18..3d0d5c36 100644
--- a/plugins/full/Makefile.am
+++ b/plugins/full/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_full_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_full_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_full_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_full_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/guestfs/Makefile.am b/plugins/guestfs/Makefile.am
index ab54daf1..120e3c7a 100644
--- a/plugins/guestfs/Makefile.am
+++ b/plugins/guestfs/Makefile.am
@@ -51,8 +51,9 @@ nbdkit_guestfs_plugin_la_CFLAGS = \
 	$(LIBGUESTFS_CFLAGS) \
 	$(NULL)
 nbdkit_guestfs_plugin_la_LIBADD = \
-	$(LIBGUESTFS_LIBS) \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(LIBGUESTFS_LIBS) \
 	$(NULL)
 nbdkit_guestfs_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/gzip/Makefile.am b/plugins/gzip/Makefile.am
index ea8bc480..ed3173ed 100644
--- a/plugins/gzip/Makefile.am
+++ b/plugins/gzip/Makefile.am
@@ -50,6 +50,7 @@ nbdkit_gzip_plugin_la_CFLAGS = \
 	$(ZLIB_CFLAGS) \
 	$(NULL)
 nbdkit_gzip_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(ZLIB_LIBS) \
 	$(NULL)
 nbdkit_gzip_plugin_la_LDFLAGS = \
diff --git a/plugins/info/Makefile.am b/plugins/info/Makefile.am
index dc55d93c..617b309c 100644
--- a/plugins/info/Makefile.am
+++ b/plugins/info/Makefile.am
@@ -53,6 +53,7 @@ nbdkit_info_plugin_la_LDFLAGS = \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
 	$(NULL)
 nbdkit_info_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(GNUTLS_LIBS) \
 	$(NULL)

diff --git a/plugins/iso/Makefile.am b/plugins/iso/Makefile.am
index 1f1f8416..ff3cfc47 100644
--- a/plugins/iso/Makefile.am
+++ b/plugins/iso/Makefile.am
@@ -54,6 +54,7 @@ nbdkit_iso_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_iso_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/libvirt/Makefile.am b/plugins/libvirt/Makefile.am
index e750e544..c26bb80f 100644
--- a/plugins/libvirt/Makefile.am
+++ b/plugins/libvirt/Makefile.am
@@ -50,6 +50,7 @@ nbdkit_libvirt_plugin_la_CFLAGS = \
 	$(LIBVIRT_CFLAGS) \
 	$(NULL)
 nbdkit_libvirt_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(LIBVIRT_LIBS) \
 	$(NULL)
 nbdkit_libvirt_plugin_la_LDFLAGS = \
diff --git a/plugins/linuxdisk/Makefile.am b/plugins/linuxdisk/Makefile.am
index 7557ee5e..0121299d 100644
--- a/plugins/linuxdisk/Makefile.am
+++ b/plugins/linuxdisk/Makefile.am
@@ -58,6 +58,7 @@ nbdkit_linuxdisk_plugin_la_LIBADD = \
 	$(top_builddir)/common/gpt/libgpt.la \
 	$(top_builddir)/common/regions/libregions.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_linuxdisk_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/lua/Makefile.am b/plugins/lua/Makefile.am
index c799de9d..f0e2b650 100644
--- a/plugins/lua/Makefile.am
+++ b/plugins/lua/Makefile.am
@@ -52,6 +52,9 @@ nbdkit_lua_plugin_la_CFLAGS = \
 	$(WARNINGS_CFLAGS) \
 	$(LUA_CFLAGS) \
 	$(NULL)
+nbdkit_lua_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_lua_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/memory/Makefile.am b/plugins/memory/Makefile.am
index a88c45c9..2270e6fe 100644
--- a/plugins/memory/Makefile.am
+++ b/plugins/memory/Makefile.am
@@ -53,6 +53,7 @@ nbdkit_memory_plugin_la_LDFLAGS = \
 nbdkit_memory_plugin_la_LIBADD = \
 	$(top_builddir)/common/allocators/liballocators.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/nbd/Makefile.am b/plugins/nbd/Makefile.am
index 671ae678..1d44b6df 100644
--- a/plugins/nbd/Makefile.am
+++ b/plugins/nbd/Makefile.am
@@ -58,6 +58,7 @@ nbdkit_nbd_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_nbd_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(LIBNBD_LIBS) \
 	$(NULL)

diff --git a/plugins/null/Makefile.am b/plugins/null/Makefile.am
index b07a70a4..1c730f48 100644
--- a/plugins/null/Makefile.am
+++ b/plugins/null/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_null_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_null_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_null_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_null_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/ondemand/Makefile.am b/plugins/ondemand/Makefile.am
index 423ac7ae..ec7ddd4a 100644
--- a/plugins/ondemand/Makefile.am
+++ b/plugins/ondemand/Makefile.am
@@ -66,6 +66,7 @@ nbdkit_ondemand_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_ondemand_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/partitioning/Makefile.am b/plugins/partitioning/Makefile.am
index d8cf9e29..36720339 100644
--- a/plugins/partitioning/Makefile.am
+++ b/plugins/partitioning/Makefile.am
@@ -61,6 +61,7 @@ nbdkit_partitioning_plugin_la_LIBADD = \
 	$(top_builddir)/common/gpt/libgpt.la \
 	$(top_builddir)/common/regions/libregions.la \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/pattern/Makefile.am b/plugins/pattern/Makefile.am
index dfbbdafa..50806d0c 100644
--- a/plugins/pattern/Makefile.am
+++ b/plugins/pattern/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_pattern_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/include \
 	$(NULL)
 nbdkit_pattern_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_pattern_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_pattern_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/perl/Makefile.am b/plugins/perl/Makefile.am
index 858ea258..b5628241 100644
--- a/plugins/perl/Makefile.am
+++ b/plugins/perl/Makefile.am
@@ -56,6 +56,7 @@ nbdkit_perl_plugin_la_CFLAGS = \
 	$(NULL)
 nbdkit_perl_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_perl_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am
index b34d0394..aacc6f22 100644
--- a/plugins/python/Makefile.am
+++ b/plugins/python/Makefile.am
@@ -58,8 +58,9 @@ nbdkit_python_plugin_la_CFLAGS = \
 	$(PYTHON_CFLAGS) \
 	$(NULL)
 nbdkit_python_plugin_la_LIBADD = \
-	$(PYTHON_LIBS) \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(PYTHON_LIBS) \
 	$(NULL)
 nbdkit_python_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/random/Makefile.am b/plugins/random/Makefile.am
index cb58831f..35a6594f 100644
--- a/plugins/random/Makefile.am
+++ b/plugins/random/Makefile.am
@@ -45,6 +45,9 @@ nbdkit_random_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_random_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_random_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_random_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/ruby/Makefile.am b/plugins/ruby/Makefile.am
index c435ff0e..b0ae24c8 100644
--- a/plugins/ruby/Makefile.am
+++ b/plugins/ruby/Makefile.am
@@ -53,6 +53,7 @@ nbdkit_ruby_plugin_la_CFLAGS = \
 	$(RUBY_CFLAGS) \
 	$(NULL)
 nbdkit_ruby_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(RUBY_LIBS) \
 	$(NULL)
 nbdkit_ruby_plugin_la_LDFLAGS = \
diff --git a/plugins/sh/Makefile.am b/plugins/sh/Makefile.am
index 77a3abde..4274b6e8 100644
--- a/plugins/sh/Makefile.am
+++ b/plugins/sh/Makefile.am
@@ -56,6 +56,7 @@ nbdkit_sh_plugin_la_CPPFLAGS = \
 nbdkit_sh_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 nbdkit_sh_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)
 nbdkit_sh_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/split/Makefile.am b/plugins/split/Makefile.am
index 209d669b..045c02f2 100644
--- a/plugins/split/Makefile.am
+++ b/plugins/split/Makefile.am
@@ -51,6 +51,7 @@ nbdkit_split_plugin_la_LDFLAGS = \
 	$(NULL)
 nbdkit_split_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/ssh/Makefile.am b/plugins/ssh/Makefile.am
index 8b2e9293..c2b0d1eb 100644
--- a/plugins/ssh/Makefile.am
+++ b/plugins/ssh/Makefile.am
@@ -52,8 +52,9 @@ nbdkit_ssh_plugin_la_CFLAGS = \
 	$(SSH_CFLAGS) \
 	$(NULL)
 nbdkit_ssh_plugin_la_LIBADD = \
-	$(SSH_LIBS) \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(SSH_LIBS) \
 	$(NULL)
 nbdkit_ssh_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
diff --git a/plugins/streaming/Makefile.am b/plugins/streaming/Makefile.am
index 7cb7e509..ef50ce58 100644
--- a/plugins/streaming/Makefile.am
+++ b/plugins/streaming/Makefile.am
@@ -44,6 +44,9 @@ nbdkit_streaming_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	$(NULL)
 nbdkit_streaming_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_streaming_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_streaming_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/plugins/tar/Makefile.am b/plugins/tar/Makefile.am
index 88909189..1db0c8f5 100644
--- a/plugins/tar/Makefile.am
+++ b/plugins/tar/Makefile.am
@@ -46,13 +46,14 @@ nbdkit_tar_plugin_la_CPPFLAGS = \
 	-I. \
 	$(NULL)
 nbdkit_tar_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_tar_plugin_la_LIBADD = \
+	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_tar_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
 	$(NULL)
-nbdkit_tar_plugin_la_LIBADD = \
-	$(top_builddir)/common/utils/libutils.la \
-	$(NULL)

 if HAVE_POD

diff --git a/plugins/tcl/Makefile.am b/plugins/tcl/Makefile.am
index b4995e24..dcb78ebc 100644
--- a/plugins/tcl/Makefile.am
+++ b/plugins/tcl/Makefile.am
@@ -52,10 +52,13 @@ nbdkit_tcl_plugin_la_CFLAGS = \
 	$(WARNINGS_CFLAGS) \
 	$(TCL_CFLAGS) \
 	$(NULL)
+nbdkit_tcl_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(TCL_LIBS) \
+	$(NULL)
 nbdkit_tcl_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
-	$(TCL_LIBS) \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/tmpdisk/Makefile.am b/plugins/tmpdisk/Makefile.am
index 69ae85e0..5542143e 100644
--- a/plugins/tmpdisk/Makefile.am
+++ b/plugins/tmpdisk/Makefile.am
@@ -60,13 +60,14 @@ nbdkit_tmpdisk_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/utils \
 	$(NULL)
 nbdkit_tmpdisk_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_tmpdisk_plugin_la_LIBADD = \
+	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_tmpdisk_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
 	$(NULL)
-nbdkit_tmpdisk_plugin_la_LIBADD = \
-	$(top_builddir)/common/utils/libutils.la \
-	$(NULL)

 if HAVE_POD

diff --git a/plugins/torrent/Makefile.am b/plugins/torrent/Makefile.am
index 0097813a..2afc39cc 100644
--- a/plugins/torrent/Makefile.am
+++ b/plugins/torrent/Makefile.am
@@ -53,14 +53,15 @@ nbdkit_torrent_plugin_la_CFLAGS = \
 	$(PTHREAD_CFLAGS) \
 	$(LIBTORRENT_CFLAGS) \
 	$(NULL)
-nbdkit_torrent_plugin_la_LDFLAGS = \
-	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
-	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
-	$(NULL)
 nbdkit_torrent_plugin_la_LIBADD = \
+	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(PTHREAD_LIBS) \
 	$(LIBTORRENT_LIBS) \
-	$(top_builddir)/common/utils/libutils.la \
+	$(NULL)
+nbdkit_torrent_plugin_la_LDFLAGS = \
+	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
+	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
 	$(NULL)

 if HAVE_POD
diff --git a/plugins/vddk/Makefile.am b/plugins/vddk/Makefile.am
index 9902d93c..95da626a 100644
--- a/plugins/vddk/Makefile.am
+++ b/plugins/vddk/Makefile.am
@@ -58,6 +58,7 @@ nbdkit_vddk_plugin_la_CPPFLAGS = \
 nbdkit_vddk_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 nbdkit_vddk_plugin_la_LIBADD = \
 	$(top_builddir)/common/utils/libutils.la \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
 	$(DL_LIBS) \
 	$(NULL)
 nbdkit_vddk_plugin_la_LDFLAGS = \
diff --git a/plugins/zero/Makefile.am b/plugins/zero/Makefile.am
index 0ec1c396..983e17d3 100644
--- a/plugins/zero/Makefile.am
+++ b/plugins/zero/Makefile.am
@@ -43,6 +43,9 @@ nbdkit_zero_plugin_la_SOURCES = \
 nbdkit_zero_plugin_la_CPPFLAGS = \
 	-I$(top_srcdir)/include
 nbdkit_zero_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
+nbdkit_zero_plugin_la_LIBADD = \
+	$(LINK_LIBNBDKIT_ON_WINDOWS) \
+	$(NULL)
 nbdkit_zero_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) \
 	-Wl,--version-script=$(top_srcdir)/plugins/plugins.syms \
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f871ac68..43783f63 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -272,6 +272,7 @@ test_stdio_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 test_stdio_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_stdio_plugin_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 # check_LTLIBRARIES won't build a shared library (see automake manual).
 # So we have to do this and add a dependency.
@@ -291,6 +292,7 @@ test_flush_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 test_flush_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_flush_plugin_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 # check_LTLIBRARIES won't build a shared library (see automake manual).
 # So we have to do this and add a dependency.
@@ -310,6 +312,7 @@ test_shutdown_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 test_shutdown_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_shutdown_plugin_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 endif HAVE_PLUGINS

@@ -364,6 +367,7 @@ test_ansi_c_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 test_ansi_c_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_ansi_c_plugin_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)
 endif CAN_TEST_ANSI_C

 if HAVE_CXX
@@ -389,6 +393,7 @@ test_cxx_plugin_la_CXXFLAGS = $(WARNINGS_CFLAGS)
 test_cxx_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_cxx_plugin_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 test_cxx_filter_la_SOURCES = \
 	test-cxx-filter.cpp \
@@ -403,6 +408,7 @@ test_cxx_filter_la_CXXFLAGS = $(WARNINGS_CFLAGS)
 test_cxx_filter_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_cxx_filter_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)
 endif HAVE_CXX

 # Exit with parent test.
@@ -1231,6 +1237,7 @@ test_layers_plugin_la_CFLAGS = $(WARNINGS_CFLAGS)
 test_layers_plugin_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_layers_plugin_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 test_layers_filter1_la_SOURCES = \
 	test-layers-filter.c \
@@ -1243,6 +1250,7 @@ test_layers_filter1_la_CFLAGS = $(WARNINGS_CFLAGS)
-Dlayer='"filter1"'
 test_layers_filter1_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_layers_filter1_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 test_layers_filter2_la_SOURCES = \
 	test-layers-filter.c \
@@ -1255,6 +1263,7 @@ test_layers_filter2_la_CFLAGS = $(WARNINGS_CFLAGS)
-Dlayer='"filter2"'
 test_layers_filter2_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_layers_filter2_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 test_layers_filter3_la_SOURCES = \
 	test-layers-filter.c \
@@ -1267,6 +1276,7 @@ test_layers_filter3_la_CFLAGS = $(WARNINGS_CFLAGS)
-Dlayer='"filter3"'
 test_layers_filter3_la_LDFLAGS = \
 	-module -avoid-version -shared $(NO_UNDEFINED_ON_WINDOWS) -rpath /nowhere \
 	$(NULL)
+test_layers_filter3_la_LIBADD = $(LINK_LIBNBDKIT_ON_WINDOWS)

 # blocksize filter test.
 TESTS += test-blocksize.sh test-blocksize-extents.sh
--
2.27.0