title: how to link with -lrt using g++
body: <p>I'm using Ubuntu 12.04.
  When I try to compile by typing, make, I get the following error:</p>
  
  <pre><code> undefined reference to `clock_gettime'
   collect2: ld returned 1 exit status
  </code></pre>
  
  <p>My makefile looks like this:</p>
  
  <pre><code>OBJS = main.o bst.o rbt.o
  OBJS_BST_TEST = bst_test.o bst.o
  OBJS_RBT_TEST = rbt_test.o bst.o rbt.o
  CC = g++
  DEBUG = -g
  CFLAGS = -std=c++0x -Wall -c $(DEBUG)
  LFLAGS = -Wall $(DEBUG)
  
  
  BSTvRBT: $(OBJS)
  $(CC) $(LFLAGS) $(OBJS) -o BSTvRBT
  
  BST_TEST: $(OBJS_BST_TEST)
  $(CC) $(LFLAGS) $(OBJS_BST_TEST) -o BST_TEST
  
  RBT_TEST: $(OBJS_BST_TEST)
  $(CC) $(LFLAGS) $(OBJS_BST_TEST) -o RBT_TEST
  
  bst_test.o: bst.h
  $(CC) $(CFLAGS) bst_test.cpp
  
  rbt_test.o: bst.h rbt.h
  $(CC) $(CFLAGS) rbt_test.cpp
  
  main.o: bst.h rbt.h
  $(CC) $(CFLAGS) main.cpp -lrt
  
  bst.o: bst.h bst.cpp exceptions.h
  $(CC) $(CFLAGS) bst.cpp
  
  rbt.o: rbt.h rbt.cpp bst.h exceptions.h
  $(CC) $(CFLAGS) rbt.cpp
  
  clean:
  \rm *.o *~ BSTvRBT BST_TEST RBT_TEST
  
  tar:
  tar cfv BSTvRBT.tar main.cpp bst.h bst.cpp rbt.h rbt.cpp exceptions.h bst_test.cpp rbt_test.cpp README.md makefile
  
  all: BSTvRBT BST_TEST RBT_TEST
  </code></pre>
  
  <p>Refer to the line starting with main.o
  In main.cpp, I have</p>
  
  <pre><code>#include &lt;time.h&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>int ret;
  timespec start;
  ret = clock_gettime(CLOCK_REALTIME, &amp;start);
  </code></pre>
  
  <p>From what I've read, I must link -lrt when compiling.
  How can I modify my makefile to do this?</p>