Skip to content

Commit fe3581e

Browse files
committed
MB-69449: Add extra libraries to gcc when __cpp_lib_stacktrace is used
From testing with gcc 13.3.0 and 14.2.0 in Ubuntu one needs to link with stdc++exp in order to get the symbols Change-Id: Ifaa074753c5c0c946f404776ecd5108994900fbd Reviewed-on: https://review.couchbase.org/c/platform/+/236726 Reviewed-by: Jim Walker <jim@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
1 parent 99c6e37 commit fe3581e

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +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.
71+
set(BACKTRACE_EXTRA_LIB "")
72+
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
73+
cmake_push_check_state(RESET)
74+
75+
check_cxx_source_compiles(
76+
"#include <stacktrace>
77+
#include <iostream>
78+
int main() {
79+
std::cout << std::to_string(std::stacktrace::current());
80+
return 0;
81+
}
82+
"
83+
HAVE_LIB_STACKTRACE_WITHOUT_EXTRA_LIB
84+
)
85+
86+
if (NOT HAVE_LIB_STACKTRACE_WITHOUT_EXTRA_LIB)
87+
set(CMAKE_REQUIRED_LIBRARIES stdc++exp)
88+
check_cxx_source_compiles(
89+
"#include <stacktrace>
90+
#include <iostream>
91+
int main() {
92+
std::cout << std::to_string(std::stacktrace::current());
93+
return 0;
94+
}
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()
104+
endif ()
105+
69106
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/include/platform/dynamic.in.h
70107
${CMAKE_CURRENT_BINARY_DIR}/include/platform/dynamic.h)
71108

@@ -297,7 +334,7 @@ foreach(platform_cbassert_variant ${platform_cbassert_VARIANTS})
297334
if (WIN32)
298335
target_link_libraries(${platform_cbassert_variant} PRIVATE DbgHelp.lib)
299336
else()
300-
target_link_libraries(${platform_cbassert_variant} PRIVATE ${CMAKE_DL_LIBS})
337+
target_link_libraries(${platform_cbassert_variant} PRIVATE ${CMAKE_DL_LIBS} ${BACKTRACE_EXTRA_LIB})
301338
endif()
302339
target_link_libraries(${platform_cbassert_variant} PRIVATE Folly::headers)
303340
endforeach()
@@ -370,7 +407,8 @@ target_link_libraries(platform PRIVATE
370407
simdutf::simdutf
371408
spdlog::spdlog
372409
${MALLOC_LIBRARIES}
373-
${PLATFORM_LIBRARIES})
410+
${PLATFORM_LIBRARIES}
411+
${BACKTRACE_EXTRA_LIB})
374412

375413
if (APPLE)
376414
if (${CMAKE_OSX_DEPLOYMENT_TARGET} VERSION_LESS "14.0")

0 commit comments

Comments
 (0)