Bug #37639 clock_gettime is never used/enabled in Linux/Unix
Submitted: 25 Jun 2008 17:24 Modified: 28 Oct 2010 9:17
Reporter: Larry Zhou Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.0.45 OS:Linux (clock_gettime is implemented in rt)
Assigned to: Magnus Blåudd CPU Architecture:Any
Tags: clock_gettime, Contribution, librt

[25 Jun 2008 17:24] Larry Zhou
Description:

clock_gettime needs librt in order to run.

The current configure.in doesn't provide rt for Linux, so HAVE_CLOCK_GETTIME is always undefined in config.h even in the system that has clock_gettime.

How to repeat:

1. Check the output of current build in linux.
   it says: checking clock_gettime ..... NO.

2. provide -lrt to compilation line in Linux
   then clock_gettime .... YES.

Suggested fix:
Here is the change to configure.in, 
AC_CHECK_LIB(rt,clock_gettime) would add -lrt to compilation line.
after that HAVE_CLOCK_GETTIME is defined.
=================
@@ -2007,9 +2007,20 @@
 	# and using AC_TRY_RUN is hard when cross-compiling
 	# We also disable for SCO for the time being, the headers for the
 	# thread library we use conflicts with other headers.
     ;;
- *) AC_CHECK_FUNCS(clock_gettime)
+ *) 
+    # most systems require the program be linked with librt library to use
+    # the function clock_gettime 
+    my_save_LIBS="$LIBS"
+    LIBS=""
+    AC_CHECK_LIB(rt,clock_gettime)
+    LIBRT=$LIBS
+    LIBS="$my_save_LIBS"
+    AC_SUBST(LIBRT)
+
+    LIBS="$LIBS $LIBRT"
+    AC_CHECK_FUNCS(clock_gettime)
     ;;
 esac
 
==========================================
[25 Jun 2008 23:18] Hartmut Holzgraefe
Verified, workaround for now:

  LDFLAGS=-lrf ./configure ...
[25 Jun 2008 23:18] Hartmut Holzgraefe
Of course it is -lrt, not -lrf:

LDFLAGS=-lrt ./configure ...
[3 Jun 2010 13:50] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/110114
[28 Oct 2010 9:17] Magnus Blåudd
Automake is being phased out -> Won't Fix