diff --git a/configure b/configure
index e9f23be5471f718b42e290c44d19634e16bc2610..810d7088245c4173efecf94991d8c1cb7230f66e 100755
--- a/configure
+++ b/configure
@@ -19205,10 +19205,6 @@ if test x$enable_universal_binary = xyes; then
    esac
 fi
 
-if ($CXX --version | grep 'clang version' > /dev/null); then
-    LDFLAGS="${LDFLAGS} -latomic"
-fi
-
 if test x$enable_sse = xyes; then
 
    if test "${ax_cv_cxx_compiler_vendor}" = "gnu"; then
@@ -23741,6 +23737,36 @@ fi
          as_fn_error $? "dlopen not found, required by Audacity" "$LINENO" 5
       fi
 
+                  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if std::atomic requires libatomic" >&5
+$as_echo_n "checking if std::atomic requires libatomic... " >&6; }
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+        #include <atomic>
+        #include <cstdint>
+        std::atomic<std::int64_t> v;
+        int main() {
+          bool f = std::atomic<double>{}.is_lock_free();
+          return v && f;
+        }
+
+_ACEOF
+if ac_fn_cxx_try_link "$LINENO"; then :
+  STD_ATOMIC_NEED_LIBATOMIC=no
+else
+  STD_ATOMIC_NEED_LIBATOMIC=yes
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+      if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then
+         LDFLAGS="${LDFLAGS} -latomic"
+         { $as_echo "$as_me:${as_lineno-$LINENO}: result: adding -latomic to LDFLAGS" >&5
+$as_echo "adding -latomic to LDFLAGS" >&6; }
+      else
+         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+      fi
+
       { $as_echo "$as_me:${as_lineno-$LINENO}: checking for gtk3 use in wxWidgets" >&5
 $as_echo_n "checking for gtk3 use in wxWidgets... " >&6; }
       CPPFLAGS="${WX_CXXFLAGS}"
diff --git a/configure.ac b/configure.ac
index 40fc326685dca2bd159321283d3d09bb0e8b7d55..dbb0c7a6672bae9c4a935c66fb7426ff1425f26f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -200,14 +200,6 @@ if test x$enable_universal_binary = xyes; then
    esac
 fi
 
-dnl Check if $CXX is clang by evaluating the version string because
-dnl $ax_cv_cxx_compiler_vendor seems not to work (it is either "gnu" or just empty).
-dnl If $CXX is clang (string is found), grep returns 0 and the if is executed.
-dnl Use /dev/null to suppress grep output to shell.
-if ($CXX --version | grep 'clang version' > /dev/null); then
-    LDFLAGS="${LDFLAGS} -latomic"
-fi
-
 if test x$enable_sse = xyes; then
 
    if test "${ax_cv_cxx_compiler_vendor}" = "gnu"; then
@@ -605,6 +597,25 @@ case "${host_os}" in
          AC_MSG_ERROR([dlopen not found, required by Audacity])
       fi
 
+      dnl Check if we need to pull in libatomic
+      dnl (assuming std::atomic is provided by libatomic in that case)
+      AC_MSG_CHECKING([if std::atomic requires libatomic])
+      AC_LINK_IFELSE([AC_LANG_SOURCE([[
+        #include <atomic>
+        #include <cstdint>
+        std::atomic<std::int64_t> v;
+        int main() {
+          bool f = std::atomic<double>{}.is_lock_free();
+          return v && f;
+        }
+      ]])], STD_ATOMIC_NEED_LIBATOMIC=no, STD_ATOMIC_NEED_LIBATOMIC=yes)
+      if test "x$STD_ATOMIC_NEED_LIBATOMIC" = xyes; then
+         LDFLAGS="${LDFLAGS} -latomic"
+         AC_MSG_RESULT([adding -latomic to LDFLAGS])
+      else
+         AC_MSG_RESULT([no])
+      fi
+
       AC_MSG_CHECKING([for gtk3 use in wxWidgets])
       CPPFLAGS="${WX_CXXFLAGS}"
       AC_EGREP_CPP(wxWidgets built with GTK3,

## diff --git a/configure b/configure
## index 44efd36dcb2926a018b1548411b8966c8bd238dd..f550c73d248600e79294c51e9f79d9d45647e867 100755
## --- a/configure
## +++ b/configure
## @@ -19208,9 +19208,13 @@ if test x$enable_universal_binary = xyes; then
##     esac
##  fi
##  
## -if ($CXX --version | grep 'clang version' > /dev/null); then
## -    LDFLAGS="${LDFLAGS} -latomic"
## -fi
## +case $host_os in
## +  linux* | gnu*)
## +    if ($CXX --version | grep 'clang version' > /dev/null); then
## +        LDFLAGS="${LDFLAGS} -latomic"
## +    fi
## +    ;;
## +esac
##  
##  if test x$enable_sse = xyes; then
##  
## diff --git a/configure.ac b/configure.ac
## index 4aadfbe6283d24db56d59f974be8adde7d91b49b..c10962af798a1b66eea1c1eaa7c42532aef95913 100644
## --- a/configure.ac
## +++ b/configure.ac
## @@ -208,9 +208,13 @@ dnl Check if $CXX is clang by evaluating the version string because
##  dnl $ax_cv_cxx_compiler_vendor seems not to work (it is either "gnu" or just empty).
##  dnl If $CXX is clang (string is found), grep returns 0 and the if is executed.
##  dnl Use /dev/null to suppress grep output to shell.
## -if ($CXX --version | grep 'clang version' > /dev/null); then
## -    LDFLAGS="${LDFLAGS} -latomic"
## -fi
## +case $host_os in
## +  linux* | gnu*)
## +    if ($CXX --version | grep 'clang version' > /dev/null); then
## +        LDFLAGS="${LDFLAGS} -latomic"
## +    fi
## +    ;;
## +esac
##  
##  if test x$enable_sse = xyes; then
##  
## 
