I am making a C program called reporter, here is the include:
#include <lcthw/dbg.h>
#include <lcthw/stats.h>
#include <stdio.h>
#include <math.h>
This is where the problem happened:
Stats_dump(stats);
Stats_dump
in Stats.c(implementation file):
void Stats_dump(Stats *st){
fprintf(stderr,"sum : %f, sumsq %f, n: %ld,min:%f, max: %f,mean: %f, stddev: %f",
st->sum,st->sumsq,st->n,st->min,st->max,Stats_mean(st),Stats_stddev(st));}
which lead to the error in Stats_stddev in Stats.h:
static inline double Stats_stddev(Stats *st){
return sqrt((st->sumsq-st->sum*st->sum/st->n)/(st->n-1)); // potential error?
}
When I run this line in makefile(build/libYOURLIBRARY.a is where I store self-made lib like stats) :
cc -g -O2 -Wall -Wextra -Isrc -rdynamic -fPIC reporter.c -lm build/libYOURLIBRARY.a -o reporter
However, it returns:
build/libYOURLIBRARY.a(stats.o): In function `Stats_stddev':
/media/thang/DATA/gay/liblcthw/src/lcthw/stats.h:17: undefined reference to `sqrt'
I have included math.h in every single file, and also add -lm to every line of makefile, but to no avail.
What might have caused this issue, and how to solve this?