diff --git a/src/conio/sdlfuncs.c b/src/conio/sdlfuncs.c
index c510724253bb98c2df50e6ccd9f216d107189b98..c76beddd421e7492f7e80ba45ecca009b88a1b8d 100644
--- a/src/conio/sdlfuncs.c
+++ b/src/conio/sdlfuncs.c
@@ -21,13 +21,17 @@ static int sdl_funcs_loaded=0;
 
 static void QuitWrap(void);
 
+static dll_handle sdl_dll;
+#ifdef _WIN32
+static dll_handle userDLL;
+static dll_handle shcoreDLL;
+#endif
 int load_sdl_funcs(struct sdlfuncs *sdlf)
 {
-	dll_handle	sdl_dll;
 	const char *libnames[]={"SDL2", "SDL", NULL};
 
 	sdlf->gotfuncs=0;
-	if((sdl_dll=xp_dlopen(libnames,RTLD_LAZY|RTLD_GLOBAL,SDL_PATCHLEVEL))==NULL)
+	if(sdl_dll == NULL && (sdl_dll=xp_dlopen(libnames,RTLD_LAZY|RTLD_GLOBAL,SDL_PATCHLEVEL))==NULL)
 		return(-1);
 
 	if((sdlf->Init=xp_dlsym(sdl_dll, SDL_Init))==NULL) {
@@ -269,7 +273,8 @@ int init_sdl_video(void)
 	HRESULT(WINAPI *SetProcessDpiAwarenessContext)(enum D3_PROCESS_DPI_AWARENESS dpiAwareness) = NULL;
 
 	const char* user32dll[] = {"User32", NULL};
-	dll_handle userDLL = xp_dlopen(user32dll, RTLD_LAZY, 0);
+	if (!userDLL)
+		userDLL = xp_dlopen(user32dll, RTLD_LAZY, 0);
 
 	if (userDLL)
 	{
@@ -279,7 +284,8 @@ int init_sdl_video(void)
 
 
 	const char* shcoredll[] = {"SHCore", NULL};
-	dll_handle shcoreDLL = xp_dlopen(shcoredll, RTLD_LAZY, 0);
+	if (!shcoreDLL)
+		shcoreDLL = xp_dlopen(shcoredll, RTLD_LAZY, 0);
 
 	if (shcoreDLL)
 	{
diff --git a/src/conio/win32gdi.c b/src/conio/win32gdi.c
index 5428214dbbdc1cd539c496cf9a8bcfd92bc0ab7f..6eaa62d775c094c05667dfb61c9c6a31d2ae11a5 100644
--- a/src/conio/win32gdi.c
+++ b/src/conio/win32gdi.c
@@ -195,6 +195,7 @@ sp_to_codepoint(uint16_t high, uint16_t low)
 	return (high - 0xd800) * 0x400 + (low - 0xdc00) + 0x10000;
 }
 
+static dll_handle userDLL;
 static BOOL
 gdiAdjustWindowRect(LPRECT r, DWORD style, BOOL menu, UINT dpi)
 {
@@ -205,7 +206,8 @@ gdiAdjustWindowRect(LPRECT r, DWORD style, BOOL menu, UINT dpi)
 
 	if (!gotPtr) {
 		const char* user32dll[] = {"User32", NULL};
-		dll_handle userDLL = xp_dlopen(user32dll, RTLD_LAZY, 0);
+		if (!userDLL)
+			userDLL = xp_dlopen(user32dll, RTLD_LAZY, 0);
 
 		if (userDLL) {
 			AWREFD = xp_dlsym(userDLL, AdjustWindowRectExForDpi);
@@ -1244,6 +1246,7 @@ gdi_get_window_info(int *width, int *height, int *xpos, int *ypos)
 	return(1);
 }
 
+static dll_handle shcoreDLL;
 int
 gdi_init(int mode)
 {
@@ -1269,7 +1272,8 @@ gdi_init(int mode)
 	HRESULT(WINAPI *SetProcessDpiAwarenessContext)(enum D3_PROCESS_DPI_AWARENESS dpiAwareness) = NULL;
 
 	const char* user32dll[] = {"User32", NULL};
-	dll_handle userDLL = xp_dlopen(user32dll, RTLD_LAZY, 0);
+	if (!userDLL)
+		userDLL = xp_dlopen(user32dll, RTLD_LAZY, 0);
 
 	if (userDLL)
 	{
@@ -1278,7 +1282,8 @@ gdi_init(int mode)
 	}
 
 	const char* shcoredll[] = {"SHCore", NULL};
-	dll_handle shcoreDLL = xp_dlopen(shcoredll, RTLD_LAZY, 0);
+	if (!shcoreDLL)
+		shcoreDLL = xp_dlopen(shcoredll, RTLD_LAZY, 0);
 
 	if (shcoreDLL)
 	{
diff --git a/src/conio/x_cio.c b/src/conio/x_cio.c
index fd37e0fda86c4e72214c0d0dd47be7c7951b6752..2bcc7ca29864f7a7ab158d0457d46d3c7af2f2e5 100644
--- a/src/conio/x_cio.c
+++ b/src/conio/x_cio.c
@@ -182,20 +182,26 @@ void x11_mouse_thread(void *data)
 	}
 }
 
+static dll_handle dl;
+#ifdef WITH_XRENDER
+static dll_handle dl2;
+#endif
+#ifdef WITH_XINERAMA
+static dll_handle dl3;
+#endif
+#ifdef WITH_XRANDR
+static dll_handle dl4;
+#endif
 int x_initciolib(int mode)
 {
-	dll_handle	dl;
 	const char *libnames[]={"X11",NULL};
 #ifdef WITH_XRENDER
-	dll_handle	dl2;
 	const char *libnames2[]={"Xrender",NULL};
 #endif
 #ifdef WITH_XINERAMA
-	dll_handle	dl3;
 	const char *libnames3[]={"Xinerama",NULL};
 #endif
 #ifdef WITH_XRANDR
-	dll_handle	dl4;
 	const char *libnames4[]={"Xrandr",NULL};
 #endif
 	Status (*xit)(void);
@@ -216,7 +222,7 @@ int x_initciolib(int mode)
 		return(-1);
 
 	/* Load X11 functions */
-	if((dl=xp_dlopen(libnames,RTLD_LAZY,7))==NULL)
+	if(dl == NULL && (dl=xp_dlopen(libnames,RTLD_LAZY,7))==NULL)
 		return(-1);
 	if ((_Xdebug = xp_dlsym(dl,_Xdebug))!=NULL)
 		*_Xdebug=1;
@@ -520,7 +526,7 @@ int x_initciolib(int mode)
 	}
 #ifdef WITH_XRENDER
 	xrender_found = true;
-	if ((dl2 = xp_dlopen(libnames2,RTLD_LAZY,1)) == NULL)
+	if (dl2 == NULL && (dl2 = xp_dlopen(libnames2,RTLD_LAZY,1)) == NULL)
 		xrender_found = false;
 	if (xrender_found && ((x11.XRenderFindStandardFormat = xp_dlsym(dl2, XRenderFindStandardFormat)) == NULL)) {
 		xp_dlclose(dl2);
@@ -557,7 +563,7 @@ int x_initciolib(int mode)
 #endif
 #ifdef WITH_XINERAMA
 	xinerama_found = true;
-	if ((dl3 = xp_dlopen(libnames3,RTLD_LAZY,1)) == NULL)
+	if (dl3 == NULL && (dl3 = xp_dlopen(libnames3,RTLD_LAZY,1)) == NULL)
 		xinerama_found = false;
 	if (xinerama_found && ((x11.XineramaQueryVersion = xp_dlsym(dl3, XineramaQueryVersion)) == NULL)) {
 		xp_dlclose(dl3);
@@ -570,7 +576,7 @@ int x_initciolib(int mode)
 #endif
 #ifdef WITH_XRANDR
 	xrandr_found = true;
-	if ((dl4 = xp_dlopen(libnames4,RTLD_LAZY,2)) == NULL)
+	if (dl4 == NULL && (dl4 = xp_dlopen(libnames4,RTLD_LAZY,2)) == NULL)
 		xrandr_found = false;
 	if (xrandr_found && ((x11.XRRQueryVersion = xp_dlsym(dl4, XRRQueryVersion)) == NULL)) {
 		xp_dlclose(dl4);
diff --git a/src/syncterm/libjxl.c b/src/syncterm/libjxl.c
index 718e69e63905d594d114e40716c91eedddace972..2446c8054aa8c5f26a27ffdb7efa22d3b44cb350 100644
--- a/src/syncterm/libjxl.c
+++ b/src/syncterm/libjxl.c
@@ -36,9 +36,12 @@ bool load_jxl_funcs(void)
 	return true;
 }
 #else
+static dll_handle jxl_dll;
+#ifdef WITH_JPEG_XL_THREADS
+static dll_handle jxlt_dll;
+#endif
 bool load_jxl_funcs(void)
 {
-	dll_handle jxl_dll;
 	const char *libnames[] = {"jxl", NULL};
 
 	if (Jxl.status == JXL_STATUS_OK)
@@ -49,7 +52,7 @@ bool load_jxl_funcs(void)
 		return false;
 
 	Jxl.status = JXL_STATUS_FAILED;
-	if ((jxl_dll = xp_dlopen(libnames, RTLD_LAZY | RTLD_GLOBAL, JPEGXL_MAJOR_VERSION)) == NULL)
+	if (jxl_dll == NULL && (jxl_dll = xp_dlopen(libnames, RTLD_LAZY | RTLD_GLOBAL, JPEGXL_MAJOR_VERSION)) == NULL)
 		return false;
 
 	if ((Jxl.DecoderCloseInput = xp_dlsym(jxl_dll, JxlDecoderCloseInput)) == NULL) {
@@ -109,7 +112,7 @@ bool load_jxl_funcs(void)
 	const char *tlibnames[] = {"jxl_threads", NULL};
 
 	Jxl.status = JXL_STATUS_FAILED;
-	if ((jxlt_dll = xp_dlopen(tlibnames, RTLD_LAZY | RTLD_GLOBAL, JPEGXL_MAJOR_VERSION)) == NULL)
+	if (jxlt_dll == NULL && (jxlt_dll = xp_dlopen(tlibnames, RTLD_LAZY | RTLD_GLOBAL, JPEGXL_MAJOR_VERSION)) == NULL)
 		return true;
 
 	if ((Jxl.ResizableParallelRunner = xp_dlsym(jxlt_dll, JxlResizableParallelRunner)) == NULL) {