Skip to content

Commit 0db9853

Browse files
ajtownsschinzelh
authored andcommitted
Add configure check for -latomic
Github-Pull: bitcoin#8563 Rebased-From: 878faac
1 parent 74394f1 commit 0db9853

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

build-aux/m4/l_atomic.m4

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Some versions of gcc/libstdc++ require linking with -latomic if
2+
# using the C++ atomic library.
3+
#
4+
# Sourced from http://bugs.debian.org/797228
5+
6+
m4_define([_CHECK_ATOMIC_testbody], [[
7+
#include <atomic>
8+
#include <cstdint>
9+
10+
int main() {
11+
std::atomic<int64_t> a{};
12+
13+
int64_t v = 5;
14+
int64_t r = a.fetch_add(v);
15+
return static_cast<int>(r);
16+
}
17+
]])
18+
19+
AC_DEFUN([CHECK_ATOMIC], [
20+
21+
AC_LANG_PUSH(C++)
22+
23+
AC_MSG_CHECKING([whether std::atomic can be used without link library])
24+
25+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
26+
AC_MSG_RESULT([yes])
27+
],[
28+
AC_MSG_RESULT([no])
29+
LIBS="$LIBS -latomic"
30+
AC_MSG_CHECKING([whether std::atomic needs -latomic])
31+
AC_LINK_IFELSE([AC_LANG_SOURCE([_CHECK_ATOMIC_testbody])],[
32+
AC_MSG_RESULT([yes])
33+
],[
34+
AC_MSG_RESULT([no])
35+
AC_MSG_FAILURE([cannot figure our how to use std::atomic])
36+
])
37+
])
38+
39+
AC_LANG_POP
40+
])

configure.ac

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ fi
5959
AC_PROG_OBJCXX
6060
])
6161

62+
dnl Check if -latomic is required for <std::atomic>
63+
CHECK_ATOMIC
64+
6265
dnl Libtool init checks.
6366
LT_INIT([pic-only])
6467

0 commit comments

Comments
 (0)