Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

undefined reference to `log'

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?

like image 872
Shade Avatar asked Feb 04 '12 22:02

Shade


People also ask

How do you fix a undefined reference?

So when we try to assign it a value in the main function, the linker doesn't find the symbol and may result in an “unresolved external symbol” or “undefined reference”. The way to fix this error is to explicitly scope the variable using '::' outside the main before using it.

How do you fix undefined references in C++?

You can fix undefined reference in C++ by investigating the linker error messages and then providing the missing definition for the given symbols. Note that not all linker errors are undefined references, and the same programmer error does not cause all undefined reference errors.

How do you fix undefined symbol in C?

The error is produced by the linker, ld . It is telling you that the symbol pow cannot be found (is undefined in all the object files handled by the linker). The solution is to include the library which includes the implementation of the pow() function, libm (m for math).

What causes unresolved external symbol?

The compiler can identify when a symbol isn't declared, but it can't tell when the symbol isn't defined. That's because the definition may be in a different source file or library. If a symbol is referred to but never defined, the linker generates an unresolved external symbol error.


1 Answers

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] 
like image 163
fajran Avatar answered Oct 08 '22 23:10

fajran