diff --git a/configure.ac b/configure.ac
index e8a8a678fdbfc04554c864cc882018a2ae4e1f72..998a7c2bf9228701159c7c8a9914a71edb1318be 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,6 +124,8 @@ fi
 
 AM_CONDITIONAL([HAVE_CUNIT], [ test "x${have_cunit}" = "xyes" ])
 
+AM_CONDITIONAL([ENABLE_SHARED], [ test "x${enable_shared}" = "xyes" ])
+
 # openssl (for examples)
 PKG_CHECK_MODULES([OPENSSL], [openssl >= 1.1.1],
                   [have_openssl=yes], [have_openssl=no])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5049123ac713bd7b241356fade93f9adbb644243..5d52ae43a2004fe515daa90eb284f2a1339c0b3a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -68,7 +68,11 @@ main_SOURCES = $(HFILES) $(OBJECTS)
 
 # With static lib disabled and symbol hiding enabled, we have to link object
 # files directly because the tests use symbols not included in public API.
+if ENABLE_SHARED
 main_LDADD = ${top_builddir}/lib/.libs/*.o
+else
+main_LDADD = ${top_builddir}/lib/.libs/libngtcp2.la
+endif
 main_LDADD += @CUNIT_LIBS@
 main_LDFLAGS = -static