直接使用make命令进行编译,出现以下错误
replication.c:961:31: error: variable has incomplete type 'struct stat64'
struct redis_stat buf;
^
replication.c:961:20: note: forward declaration of 'struct stat64'
struct redis_stat buf;
^
./config.h:46:20: note: expanded from macro 'redis_stat'
#define redis_stat stat64
^
replication.c:1007:21: error: call to undeclared function 'fstat64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
redis_fstat(slave->repldbfd,&buf) == -1) {
根据https://github.com/redis/redis/issues/12585所述,在config.h中新增一行:
#ifndef __CONFIG_H
#define __CONFIG_H
#ifdef __APPLE__
#define _DARWIN_C_SOURCE <-新增该行
#include <AvailabilityMacros.h>
#endif
...
再次进行编译,又回遇到以下问题:
debug.c:750:42: error: no member named '__eip' in 'struct __darwin_arm_thread_state64'
return (void*) uc->uc_mcontext->__ss.__eip;
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:844:47: error: no member named '__eax' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__eax,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:845:47: error: no member named '__ebx' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__ebx,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:846:47: error: no member named '__ecx' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__ecx,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:847:47: error: no member named '__edx' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__edx,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:848:47: error: no member named '__edi' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__edi,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:849:47: error: no member named '__esi' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__esi,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:850:47: error: no member named '__ebp' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__ebp,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:851:47: error: no member named '__esp' in 'struct __darwin_arm_thread_state64'; did you mean '__sp'?
(unsigned long) uc->uc_mcontext->__ss.__esp,
^~~~~
__sp
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/arm/_structs.h:141:13: note: '__sp' declared here
__uint64_t __sp; /* Stack pointer x31 */
^
debug.c:852:47: error: no member named '__ss' in 'struct __darwin_arm_thread_state64'; did you mean '__sp'?
(unsigned long) uc->uc_mcontext->__ss.__ss,
^~~~
__sp
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/arm/_structs.h:141:13: note: '__sp' declared here
__uint64_t __sp; /* Stack pointer x31 */
^
debug.c:853:47: error: no member named '__eflags' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__eflags,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:854:47: error: no member named '__eip' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__eip,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:855:47: error: no member named '__cs' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__cs,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:856:47: error: no member named '__ds' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__ds,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:857:47: error: no member named '__es' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__es,
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:858:47: error: no member named '__fs' in 'struct __darwin_arm_thread_state64'; did you mean '__fp'?
(unsigned long) uc->uc_mcontext->__ss.__fs,
^~~~
__fp
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/mach/arm/_structs.h:139:13: note: '__fp' declared here
__uint64_t __fp; /* Frame pointer x29 */
^
debug.c:859:47: error: no member named '__gs' in 'struct __darwin_arm_thread_state64'
(unsigned long) uc->uc_mcontext->__ss.__gs
~~~~~~~~~~~~~~~~~~~~~ ^
debug.c:861:51: error: no member named '__esp' in 'struct __darwin_arm_thread_state64'; did you mean '__sp'?
logStackContent((void**)uc->uc_mcontext->__ss.__esp);
^~~~~
__sp
经过搜索应用一个patch可以解决:03-REIDS-APPLE-SILCON-CHIP.patch (https://github.com/RedisOptimal/redis-cluster-support-mget/blob/c0ad6cb108d29f795f87f7abb0de63650b185499/03-REIDS-APPLE-SILCON-CHIP.patch)
将patch文件复制到redis源码根目录,使用命令应用patch:git apply xxx.patch
再次make可以编译成功,测试启动正常: