diff --git a/subprojects/libnpupnp.wrap b/subprojects/libnpupnp.wrap
index e6cba215a..83865ad75 100644
--- a/subprojects/libnpupnp.wrap
+++ b/subprojects/libnpupnp.wrap
@@ -6,5 +6,8 @@ source_hash = d83cadc997a5367030820de6c4a49130b38fe605bf3d0d2c939d7d1c06aa3226
 source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/libnpupnp_6.1.2-1/libnpupnp-6.1.2.tar.gz
 wrapdb_version = 6.1.2-1
 
+# https://github.com/medoc92/npupnp/commit/bb59a9d961efb3c88999f02204bd7cfb5cb45e54
+diff_files = libnpupnp_gcc14.patch
+
 [provide]
 libnpupnp = libnpupnp_dep
diff --git a/subprojects/packagefiles/libnpupnp_gcc14.patch b/subprojects/packagefiles/libnpupnp_gcc14.patch
new file mode 100644
index 000000000..cb253bd83
--- /dev/null
+++ b/subprojects/packagefiles/libnpupnp_gcc14.patch
@@ -0,0 +1,66 @@
+From bb59a9d961efb3c88999f02204bd7cfb5cb45e54 Mon Sep 17 00:00:00 2001
+From: Rosen Penev <rosenp@gmail.com>
+Date: Wed, 24 Apr 2024 15:01:26 -0700
+Subject: [PATCH] fix compilation with GCC14
+
+algorithm include is needed.
+
+Signed-off-by: Rosen Penev <rosenp@gmail.com>
+---
+ src/api/upnpapi.cpp         | 1 +
+ src/ssdp/ssdp_ctrlpt.cpp    | 1 +
+ src/webserver/webserver.cpp | 8 ++++----
+ 3 files changed, 6 insertions(+), 4 deletions(-)
+
+diff --git a/src/api/upnpapi.cpp b/src/api/upnpapi.cpp
+index 3765f5b..cce88fb 100644
+--- a/src/api/upnpapi.cpp
++++ b/src/api/upnpapi.cpp
+@@ -32,6 +32,7 @@
+ 
+ #include "config.h"
+ 
++#include <algorithm>
+ #include <array>
+ #include <mutex>
+ #include <sstream>
+diff --git a/src/ssdp/ssdp_ctrlpt.cpp b/src/ssdp/ssdp_ctrlpt.cpp
+index bfddf95..0f41649 100644
+--- a/src/ssdp/ssdp_ctrlpt.cpp
++++ b/src/ssdp/ssdp_ctrlpt.cpp
+@@ -36,6 +36,7 @@ nnn * Redistribution and use in source and binary forms, with or without
+ #ifdef INCLUDE_CLIENT_APIS
+ #if EXCLUDE_SSDP == 0
+ 
++#include <algorithm>
+ #include <chrono>
+ #include <cstring>
+ #include <iostream>
+diff --git a/src/webserver/webserver.cpp b/src/webserver/webserver.cpp
+index c427db3..d6184f0 100644
+--- a/src/webserver/webserver.cpp
++++ b/src/webserver/webserver.cpp
+@@ -43,11 +43,12 @@
+ 
+ #include "webserver.h"
+ 
++#include <algorithm>
++#include <cassert>
++#include <cinttypes>
+ #include <map>
+-#include <unordered_map>
+ #include <mutex>
+-
+-#include <cinttypes>
++#include <unordered_map>
+ 
+ #include "genut.h"
+ #include "ssdplib.h"
+@@ -55,7 +56,6 @@
+ #include "upnpapi.h"
+ #include "uri.h"
+ 
+-#include <cassert>
+ #include <fcntl.h>
+ #include <sys/stat.h>
+