31

I am trying to compile the implementation of the RFC 3797 random selection algorithm by Donald Eastlake (code: http://kambing.ui.ac.id/minix/other/rfc3797/). However, I am getting a linker error:

rfc3797.c:(.text+0xe7f): undefined reference to `log'

I am trying to make it with the provided Makefile, which explicitly links against the math libraray, but I still get the error:

cc -lm -o randomselection rfc3797.c MD5.c

How can I compile this program?

Shade
  • 9,936
  • 5
  • 60
  • 85
  • 4
    Can you try `cc -o randomselection rfc3797.c MD5.c -lm` ? – cnicutar Feb 04 '12 at 22:43
  • 1
    @Shade No, it's okay, I'm glad it's working :-) You can accept fajrans answer instead. And here's a [C FAQ](http://c-faq.com/lib/libsearch.html) on the subject. – cnicutar Feb 04 '12 at 23:02
  • Trying to implement an RFC -> get compile-time errors -> take the error to google (which is really quite a generic error) -> top result is someone else having an issue with that same RFC. There is some beauty to that. – Luc Sep 03 '17 at 01:28

1 Answers1

48

I don't know what the reason is, but if you move -lm to the end, it will compile.

$ cc -o randomselection rfc3797.c MD5.c -lm
rfc3797.c: In function ‘getinteger’:
rfc3797.c:183:3: warning: format not a string literal and no format arguments [-Wformat-security]
fajran
  • 2,769
  • 22
  • 13
  • 1
    To expand on what Kerrek is referring to, and borrowing from cnicutar above, this explains how linking works with reference to argument order: http://c-faq.com/lib/libsearch.html – staticfloat Nov 27 '12 at 20:11