Skip to content
Snippets Groups Projects
Commit 960e9c0c authored by Alexander V. Tikhonov's avatar Alexander V. Tikhonov Committed by Kirill Yukhin
Browse files

build: fix unit tests build with -lrt on CentOS 6

After the commit 77fa45bd
('lua: add fiber.top() listing fiber cpu consumption')
the unit tests builds failed like:

/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld:
  ../../src/lib/core/libcore.a(fiber.c.o): undefined reference to symbol
  'clock_gettime@@GLIBC_2.2.5'
//lib64/librt.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
test/unit/CMakeFiles/cbus.test.dir/build.make:108: recipe for target
  'test/unit/cbus.test' failed
make[2]: *** [test/unit/cbus.test] Error 1

Found that fiber.cc is using now clock_gettime(), which requires -lrt
with glibc. To fix it added librt dependency for core library for glibc.
Due to glibc requires for -lrt for clock_gettime() only for some
versions, check 'man clock_gettime.2':
  'Link with -lrt (only for glibc versions before 2.17).'
the check whether is able to use clock_gettime() w/o librt library is
added.

Close #4639

(cherry picked from commit 99b0ef771135eab66ef3758371b1b5431e21cbff)
parent bf20a7ce
No related branches found
No related tags found
No related merge requests found
...@@ -116,6 +116,12 @@ else () ...@@ -116,6 +116,12 @@ else ()
set(HAVE_CLOCK_GETTIME ${HAVE_CLOCK_GETTIME_DECL}) set(HAVE_CLOCK_GETTIME ${HAVE_CLOCK_GETTIME_DECL})
endif () endif ()
set(CMAKE_REQUIRED_LIBRARIES "") set(CMAKE_REQUIRED_LIBRARIES "")
# According to `man 2 clockgettime` the glibc wrapper requires
# -lrt on glibc versions before 2.17. We need to check whether
# the function is available without -lrt to set this linker option
# conditionally.
check_function_exists(clock_gettime HAVE_CLOCK_GETTIME_WITHOUT_RT)
check_symbol_exists(__get_cpuid cpuid.h HAVE_CPUID) check_symbol_exists(__get_cpuid cpuid.h HAVE_CPUID)
# Checks for libev # Checks for libev
......
...@@ -46,3 +46,11 @@ target_link_libraries(core salad small uri decNumber ${LIBEV_LIBRARIES} ...@@ -46,3 +46,11 @@ target_link_libraries(core salad small uri decNumber ${LIBEV_LIBRARIES}
if (ENABLE_BACKTRACE AND NOT TARGET_OS_DARWIN) if (ENABLE_BACKTRACE AND NOT TARGET_OS_DARWIN)
target_link_libraries(core gcc_s ${UNWIND_LIBRARIES}) target_link_libraries(core gcc_s ${UNWIND_LIBRARIES})
endif() endif()
# Since fiber.top() introduction, fiber.cc, which is part of core
# library, depends on clock_gettime() syscall, so we should set
# -lrt when it is appropriate. See a comment for
# HAVE_CLOCK_GETTIME_WITHOUT_RT in ${REPO}/CMakeLists.txt.
if ("${HAVE_CLOCK_GETTIME}" AND NOT "${HAVE_CLOCK_GETTIME_WITHOUT_RT}")
target_link_libraries(core rt)
endif()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment