copy_fetch.c:161:1: error: conflicting types for 'copy_file_range'


背景

项目需要为适配“中标麒麟 Ky10”操作系统,需要部署PostgreSQL 9.6。我是通过源码安装PG,一台正常,另外一台在make时报如下错误:

copy_fetch.c:161:1: error: conflicting types for 'copy_file_range'
 copy_file_range(const char *path, off_t begin, off_t end, bool trunc)
 ^~~~~~~~~~~~~~~
In file included from copy_fetch.c:16:
/usr/include/unistd.h:1107:9: note: previous declaration of 'copy_file_range' was here
 ssize_t copy_file_range (int __infd, __off64_t *__pinoff,
         ^~~~~~~~~~~~~~~
make[3]: *** [: copy_fetch.o] Error 1
make[3]: Leaving directory '/home/postgresql-9.6.0/src/bin/pg_rewind'
make[2]: *** [Makefile:40: all-pg_rewind-recurse] Error 2
make[2]: Leaving directory '/home/postgresql-9.6.0/src/bin'
make[1]: *** [Makefile:36: all-bin-recurse] Error 2
make[1]: Leaving directory '/home/postgresql-9.6.0/sr

解决办法

在解压的安装包目录下找到copy_fetch.c,替换copy_file_range为copy_file_chunk:

[root]# sed -i 's/copy_file_range/copy_file_chunk/g' /postgresql-9.6.0/src/bin/pg_rewind/copy_fetch.c

重新源码编译