Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to compile the program the source for which is here. As per his instructions I'm compiling using the command g++ -O3 -lrt netmon.cpp -o netmon. I get this output:

netmon.cpp:(.text.startup+0xb3): undefined reference to `clock_gettime'
collect2: ld returned 1 exit status

This is odd as I have read that the rt library provides this function. What is going on?

share|improve this question

gcc and g++ can be picky about the order of link arguments. In general, you should specify library arguments (-l) after local objects. Try this instead:

g++ -O3 netmon.c -o netmon -lrt
share|improve this answer
I tried this but it didn't work either. I eventually compiled with gcc instead and that worked. Very strange. Thanks for your input. – sennett Jul 15 '12 at 11:27

I eventually used gcc instead and it worked:

gcc -o netmon netmon.cpp -lrt
share|improve this answer
This does not really answer the question, but it solved my problem. – sennett Jul 15 '12 at 11:30

Add -lrt after the source file, example:

g++ -O3 -o netmon netmon.cpp -lrt

Here is an other discussion about the same problem.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.