Skip to content

Commit a5020b6

Browse files
laanwjcodablock
authored andcommitted
Merge bitcoin#8563: Add configure check for -latomic
878faac Add configure check for -latomic (Anthony Towns)
1 parent f0813d6 commit a5020b6

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ case $host in
5656
esac
5757
dnl Require C++11 compiler (no GNU extensions)
5858
AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory], [nodefault])
59+
dnl Check if -latomic is required for <std::atomic>
60+
CHECK_ATOMIC
5961

6062
dnl Unless the user specified OBJCXX, force it to be the same as CXX. This ensures
6163
dnl that we get the same -std flags for both.

0 commit comments

Comments
 (0)