diff --git a/meson.build b/meson.build
index 63e45465da9c..e3052260f13e 100644
--- a/meson.build
+++ b/meson.build
@@ -112,6 +112,8 @@ common_arguments = [
 c_arguments = []
 cpp_arguments = []
 
+cxx_stdlib = 'libstdc++'
+
 if cc.get_id() == 'clang'
     if cc.version().version_compare('<9')
         error('clang version is too old, libcamera requires 9.0 or newer')
@@ -137,6 +139,7 @@ if cc.get_id() == 'clang'
         cpp_arguments += [
             '-stdlib=libc++',
         ]
+        cxx_stdlib = 'libc++'
     endif
 
     cpp_arguments += [
diff --git a/test/py/meson.build b/test/py/meson.build
index 481bb481c110..b922e8578c29 100644
--- a/test/py/meson.build
+++ b/test/py/meson.build
@@ -24,6 +24,12 @@ py_env.append('PYTHONPATH', pypathdir)
 if asan_enabled
     py_env.append('LD_PRELOAD', asan_runtime)
 
+    # Preload the C++ standard library to work around a bug in ASan when
+    # dynamically loading C++ .so modules.
+    stdlib = run_command(cxx, '-print-file-name=' + cxx_stdlib + '.so',
+                         check : true).stdout().strip()
+    py_env.append('LD_PRELOAD', stdlib)
+
     # Disable leak detection as the Python interpreter is full of leaks.
     py_env.append('ASAN_OPTIONS', 'detect_leaks=0')
 endif
