When i compile the following code snippet I get this error message from my compiler:
/tmp/ccT1yBa1.o: In function `main':
test.c:(.text.startup+0x34): undefined reference to `log'
collect2: error: ld returned 1 exit status
_
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <math.h>
void main(){
srand(time(NULL));
double r1 = (rand() % 1000)/1000.0;
double r2 = log(r1);
printf("%lf\n",r2);
}
Compiled with
gcc -O2 test.c
What's wrong?