编译redis3.2.7的时候,make出现以下错误:

../deps/jemalloc/lib/libjemalloc.a(nstime.o): In function `nstime_get':
/usr/local/src/redis-3.2.7/deps/jemalloc/src/nstime.c:120: undefined reference to `clock_gettime'
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/usr/local/src/redis-3.2.7/src'
make: *** [all] Error 2


查了一下资料,发现是类库问题

on older linux systems,clock_gettime() is in librt rather than libc.

也就是说在版本比较老的linux系统中,clock_gettime这个函数是在librt库中的函数。

redis3.2.7调用的可能是新版的,所以需要在Makefile中指定


修改../redis-3.2.7/src/Makefile

 FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a

改为

 FINAL_LIBS+= ../deps/jemalloc/lib/libjemalloc.a -lrt