编译PostgreSQL时提示conflicting types for copy_file_range的解决方法
问题现象描述
在ARM服务器编译PostgreSQL 10.1及以上版本时,提示“copy_fetch.c:159:1: error: conflicting types for 'copy_file_range'”。详细提示信息如下:
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2 -I../../../src/interfaces/libpq -DFRONTEND -I../../../src/include -D_GNU_SOURCE -c -o copy_fetch.o copy_fetch.ccopy_fetch.c:159: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:15:0:/usr/include/unistd.h:1110:9: note: previous declaration of 'copy_file_range' was heressize_t copy_file_range (int infd, __off64_t *pinoff,^~~~~~~~~~~~~~~
关键过程、根本原因分析
copy_file_range是Linux 4.5版本引入的系统调用,而在较早的Linux版本中并不支持该调用。因此,如果在旧版本的Linux系统中编译使用copy_file_range函数,会导致编译问题。而将copy_file_range改为copy_file_chunk,则可以避免这个问题,并且在较旧的Linux系统中也能够正常编译和使用。
结论、解决方案及效果
- 查找copy_fetch.c文件的位置。
find / -name copy_fetch.c
发现copy_fetch.c文件在postgresql-10.1.tar.gz源码解压路径postgresql-10.1的子路径“src/bin/pg_rewind/”中。
- 进入postgresql-10.1.tar.gz源码解压路径postgresql-10.1,修改copy_fetch.c中所有函数名copy_file_range为copy_file_chunk。
sed -i "s/copy_file_range/copy_file_chunk/g" src/bin/pg_rewind/copy_fetch.c
- 重新执行编译安装PostgreSQL命令。
make && make install
父主题: PostgreSQL