Centos7 安装 redis 6 编译错误

错误日志

In file included from server.c:30:0:
server.h:1044:5: error: expected specifier-qualifier-list before ‘_Atomic’
     _Atomic unsigned int lruclock; /* Clock for LRU eviction */
     ^
server.c: In function ‘serverLogRaw’:
server.c:1028:31: error: ‘struct redisServer’ has no member named ‘logfile’
     int log_to_stdout = server.logfile[0] == '\0';
                               ^
server.c:1031:23: error: ‘struct redisServer’ has no member named ‘verbosity’
     if (level < server.verbosity) return;
                       ^
server.c:1033:47: error: ‘struct redisServer’ has no member named ‘logfile’
     fp = log_to_stdout ? stdout : fopen(server.logfile,"a");
                                               ^
server.c:1046:47: error: ‘struct redisServer’ has no member named ‘timezone’
         nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
                                               ^
server.c:1046:63: error: ‘struct redisServer’ has no member named ‘daylight_active’
         nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
                                                               ^
server.c:1049:19: error: ‘struct redisServer’ has no member named ‘sentinel_mode’

...

server.c:5103:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
         if (server.supervised_mode == SUPERVISED_SYSTEMD) {
                   ^
server.c:5104:24: error: ‘struct redisServer’ has no member named ‘masterhost’
             if (!server.masterhost) {
                        ^
server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
               ^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
                                       ^
server.c:5118:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
         serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);

                                 ^
server.c: In function ‘hasActiveChildProcess’:
server.c:1476:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘allPersistenceDisabled’:
server.c:1482:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3747:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘iAmMaster’:
server.c:4914:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/root/redis-6.0.1/src'
make: *** [all] Error 2

原因

自 redis 6.0.0 之后,编译 redis 需要支持 C11 特性

Centos7 默认 gcc 版本为 4.8.5C11 特性在 4.9 中引入

解决方案

安装 Developer Toolset 7 使用 gcc 7 编译

yum install centos-release-scl devtoolset-7

这不会更新系统原有 gcc 软件包,在当您需要使用 gcc 7 工具链时,使用下列命令进入环境

scl enable devtoolset-7 bash

安装

wget https://github.com/antirez/redis/archive/6.0.1.tar.gz
tar -xvzf 6.0.1.tar.gz
cd redis-6.0.1
./configure
make
make install

其他 devtoolset 版本

版权所有,转载请注明文章来源
本文链接:https://www.limstash.com/articles/202005/1633
本文标题:Centos7 安装 redis 6 编译错误
如有疑问,请邮件联系,联系方式可见隐私政策