Skip to content

Commit fbaaf0c

Browse files
committed
MB-69449: clang may also need stdc++exp
clang-18.1.3 on Ununtu 24 fails with the same error as newer versions of g++ Change-Id: I8915300dbbb6747efa9cbe54a244f6d9ac08844b Reviewed-on: https://review.couchbase.org/c/platform/+/237425 Tested-by: Build Bot <build@couchbase.com> Reviewed-by: Mohammad Zaeem <mohammad.zaeem@couchbase.com>
1 parent 92f1a5a commit fbaaf0c

2 files changed

Lines changed: 32 additions & 28 deletions

File tree

CMakeLists.txt

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,43 +66,43 @@ else(WIN32)
6666
endif()
6767
endif(WIN32)
6868

69-
# Some versions of GCC needs an explicit link to stdc++exp to get
70-
# stacktrace support.
69+
# Some versions of GCC / clang needs an explicit link to stdc++exp
70+
# to get stacktrace support.
7171
set(BACKTRACE_EXTRA_LIB "")
72-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
73-
cmake_push_check_state(RESET)
72+
cmake_push_check_state(RESET)
7473

75-
check_cxx_source_compiles(
76-
"#include <stacktrace>
74+
check_cxx_source_compiles(
75+
"#include <stacktrace>
7776
#include <iostream>
7877
int main() {
79-
std::cout << std::to_string(std::stacktrace::current());
80-
return 0;
78+
std::cout << std::to_string(std::stacktrace::current());
79+
return 0;
8180
}
82-
"
83-
HAVE_LIB_STACKTRACE_WITHOUT_EXTRA_LIB
84-
)
81+
"
82+
HAVE_LIB_STACKTRACE_WITHOUT_EXTRA_LIB
83+
)
8584

86-
if (NOT HAVE_LIB_STACKTRACE_WITHOUT_EXTRA_LIB)
87-
set(CMAKE_REQUIRED_LIBRARIES stdc++exp)
88-
check_cxx_source_compiles(
89-
"#include <stacktrace>
85+
if (NOT HAVE_LIB_STACKTRACE_WITHOUT_EXTRA_LIB)
86+
set(CMAKE_REQUIRED_LIBRARIES stdc++exp)
87+
check_cxx_source_compiles(
88+
"#include <stacktrace>
9089
#include <iostream>
9190
int main() {
92-
std::cout << std::to_string(std::stacktrace::current());
93-
return 0;
91+
std::cout << std::to_string(std::stacktrace::current());
92+
return 0;
9493
}
95-
"
96-
HAVE_LIB_STACKTRACE_WITH_EXTRA_LIB
97-
)
98-
if (HAVE_LIB_STACKTRACE_WITH_EXTRA_LIB)
99-
set(BACKTRACE_EXTRA_LIB "stdc++exp")
100-
endif (HAVE_LIB_STACKTRACE_WITH_EXTRA_LIB)
101-
endif ()
102-
103-
cmake_pop_check_state()
94+
"
95+
HAVE_LIB_STACKTRACE_WITH_EXTRA_LIB
96+
)
97+
if (HAVE_LIB_STACKTRACE_WITH_EXTRA_LIB)
98+
set(BACKTRACE_EXTRA_LIB "stdc++exp")
99+
else ()
100+
add_definitions(-DSTD_STACKTRACE_WONT_WORK=1)
101+
endif (HAVE_LIB_STACKTRACE_WITH_EXTRA_LIB)
104102
endif ()
105103

104+
cmake_pop_check_state()
105+
106106
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/include/platform/dynamic.in.h
107107
${CMAKE_CURRENT_BINARY_DIR}/include/platform/dynamic.h)
108108

src/backtrace.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
#include <execinfo.h> // for backtrace()
2222
#endif
2323

24-
#if __cpp_lib_stacktrace
24+
#if defined(__cpp_lib_stacktrace) && !defined(STD_STACKTRACE_WONT_WORK)
25+
#define HAVE_STD_STACKTRACE_SUPPORT 1
26+
#endif
27+
28+
#if HAVE_STD_STACKTRACE_SUPPORT
2529
#include <stacktrace>
2630
#endif
2731

@@ -207,7 +211,7 @@ void cb::backtrace::initialize() {
207211

208212
namespace cb::backtrace {
209213

210-
#if __cpp_lib_stacktrace
214+
#if HAVE_STD_STACKTRACE_SUPPORT
211215
[[nodiscard]] std::string current() {
212216
return std::to_string(std::stacktrace::current());
213217
}

0 commit comments

Comments
 (0)