1 From 54b8977c2f854d04f9c6383e2cac76ea4cde3eaa Mon Sep 17 00:00:00 2001
2 From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3 Date: Mon, 29 Dec 2014 12:23:41 +0100
4 Subject: [PATCH] Link mcaptest with -lrt when needed
6 The mcaptest tool uses the profiles/health/mcap.c source file, which
7 calls clock_getres(). This function is defined in librt in some C
8 libraries, so mcaptest should be linked against librt when needed,
9 otherwise one gets link failures such as:
11 ld: profiles/health/mcap.o: undefined reference to symbol 'clock_getres@@GLIBC_2.2.5'
12 ld: note: 'clock_getres@@GLIBC_2.2.5' is defined in DSO [...]/sysroot/lib64/librt.so.1 so try adding it to the linker command line
13 [...]/sysroot/lib64/librt.so.1: could not read symbols: Invalid operation
14 collect2: error: ld returned 1 exit status
15 Makefile:4184: recipe for target 'tools/mcaptest' failed
17 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
20 configure.ac | 5 +++++
21 2 files changed, 6 insertions(+), 1 deletion(-)
23 diff --git a/Makefile.tools b/Makefile.tools
24 index bc827fe..fef3db5 100644
27 @@ -195,7 +195,7 @@ tools_mcaptest_SOURCES = tools/mcaptest.c \
28 btio/btio.h btio/btio.c \
30 profiles/health/mcap.h profiles/health/mcap.c
31 -tools_mcaptest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
32 +tools_mcaptest_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@ @RT_LIBS@
34 dist_man_MANS += tools/hciattach.1 tools/hciconfig.1 \
35 tools/hcitool.1 tools/hcidump.1 \
36 diff --git a/configure.ac b/configure.ac
37 index 4739c10..b0afba6 100644
40 @@ -54,6 +54,11 @@ AC_CHECK_LIB(pthread, pthread_create, dummy=yes,
41 AC_CHECK_LIB(dl, dlopen, dummy=yes,
42 AC_MSG_ERROR(dynamic linking loader is required))
44 +AC_SEARCH_LIBS([clock_getres], [rt],
45 + [test "$ac_cv_search_clock_getres" = "none required" ||
46 + RT_LIBS=$ac_cv_search_clock_getres])
49 PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.28, dummy=yes,
50 AC_MSG_ERROR(GLib >= 2.28 is required))