title: Undefined reference to clock_gettime, gcc 4.6 & cmake
body: <p>I'm having a link error under cmake that I don't have when compiling on a system with an older version of gcc.</p>
  
  <p>The specific error is "undefined reference to <code>clock_gettime</code>"
  but <code>-lrt</code> is appearing on the command line.</p>
  
  <p>My gcc version:</p>
  
  <pre><code>gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
  Copyright (C) 2011 Free Software Foundation, Inc.
  This is free software; see the source for copying conditions.  There is NO
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  </code></pre>
  
  <p>cmake version 2.8.5</p>
  
  <p>I am including the required "-lrt" through target_link_libraries in my CMakeLists.txt file.
  I can see it appear in the compiler line with make VERBOSE=1</p>
  
  <p>I've read that gcc 4.6 is picky about the position of link libraries on the command line.</p>
  
  <p>How can I fix this for CMake?</p>
  
  <p>EDIT:
  Link line</p>
  
  <pre><code>Linking CXX executable ../bin/obbsd
  cd /home/matt/Desktop/Matt/OBBS/Build/server &amp;&amp; /usr/bin/cmake -E cmake_link_script \
       CMakeFiles/obbsd.dir/link.txt --verbose=1   
  /usr/bin/c++   -g    CMakeFiles/obbsd.dir/Block.cpp.o \
       CMakeFiles/obbsd.dir/BlockFileCache.cpp.o \
        CMakeFiles/obbsd.dir/BlockFileStore.cpp.o \
        CMakeFiles/obbsd.dir/BlockMemoryCache.cpp.o \
        CMakeFiles/obbsd.dir/BlockStore.cpp.o CMakeFiles/obbsd.dir/Config.cpp.o \
        CMakeFiles/obbsd.dir/DeleteBlockSession.cpp.o \
        CMakeFiles/obbsd.dir/mConfigFile.cpp.o \
        CMakeFiles/obbsd.dir/mNetworkPacketReader.cpp.o \
        CMakeFiles/obbsd.dir/mNetworkPacketWriter.cpp.o \
        CMakeFiles/obbsd.dir/obbsd.cpp.o \
        CMakeFiles/obbsd.dir/ReadBlockSession.cpp.o CMakeFiles/obbsd.dir/Server.cpp.o \
        CMakeFiles/obbsd.dir/Session.cpp.o CMakeFiles/obbsd.dir/Utility.cpp.o \
        CMakeFiles/obbsd.dir/WriteBlockSession.cpp.o  -o ../bin/obbsd -rdynamic \
        -lpthread -lrt ../lib/libLibUtil.a 
  ../lib/libLibUtil.a(mTimer.cpp.o): In function `mTimer::GetTick()':
  /home/matt/Desktop/Matt/OBBS/LibUtil/src/mTimer.cpp:108: undefined reference to
       `clock_gettime'
  </code></pre>
  
  <p>Why is ../lib/libLibUtil.a appearing after -lrt when LibUtil (what would be libLibUtil.a) is before rt?</p>
  
  <p>CMakeLists.txt includes...</p>
  
  <pre><code>...
  add_executable(obbsd ${SERVER_SOURCE_FILES})
  find_package(Threads REQUIRED)
  target_link_libraries(obbsd ${CMAKE_THREAD_LIBS_INIT} LibUtil rt)
  </code></pre>