From 66198f447f45a87718b6457756976baa8defb2fd Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Fri, 10 Apr 2020 13:30:00 -0400 Subject: Use -latomic if needed with gcc --- configure.ac | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'configure.ac') diff --git a/configure.ac b/configure.ac index 9a887b90..a3c3d064 100644 --- a/configure.ac +++ b/configure.ac @@ -240,6 +240,32 @@ for i in 0 1; do done AC_LANG_POP +AC_LANG_PUSH([C++]) +AC_MSG_CHECKING(whether to use -latomic) +dnl On some platforms with some versions of gcc, you have to link with +dnl -latomic in order for std::atomic to work. Passing --as-needed +dnl prevents unnecessary linking with -latomic. +oLDFLAGS="$LDFLAGS" +LDFLAGS="$LDFLAGS -Wl,--as-needed -latomic" +AC_LINK_IFELSE([AC_LANG_SOURCE( + [[#include + int main() + { + static std::atomic a{0}; + a = a.fetch_add(1); + return 0; + } + ]])], + [qpdf_USE_ATOMIC=1], + [qpdf_USE_ATOMIC=0]) +if test "$qpdf_USE_ATOMIC" = "1"; then + AC_MSG_RESULT(yes) +else + AC_MSG_RESULT(no) + LDFLAGS="$oLDFLAGS" +fi +AC_LANG_POP + if test "x$qpdf_OS_SECURE_RANDOM" = "x1"; then OLIBS=$LIBS LIBS="$LIBS Advapi32.lib" -- cgit v1.2.3-54-g00ecf