编译PostgreSQL 9.6的C函数时出错

我正在升级到PostgreSQL 9.6并在尝试编译一些C代码时遇到一些错误。

gcc -c -o lib/libhaver.o src/libhaver.c -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fPIC -D_GNU_SOURCE -I. -I/usr/pgsql-9.6/include/server -I/usr/pgsql-9.6/include/server/access -I/usr/pgsql-9.6/include/internal -I/usr/include/et -I/usr/include/libxml2 -I/usr/include 

这段代码:

 #include "postgres.h" #include "fmgr.h" #include "catalog/pg_type.h" #include "funcapi.h" #include "utils/guc.h" #include "access/htup.h" #include "utils/array.h" #include "math.h" #ifdef NEWPOSTGRES #include "access/htup_details.h" #endif PG_MODULE_MAGIC; // Define a missing value that we can insert into our array # define FLOAT_NaN (0.0/0.0) int32 mapAtoB(int32 i, int32 a2, int32 a1); PG_FUNCTION_INFO_V1( mapAtoB ); int32 mapAtoB(int32 i, int32 a2, int32 a1){ int32 j = (i - (a1-a2)); return j; } 

但是我收到此错误:

 src/libhaver.c:30: error: conflicting types for 'mapAtoB' src/libhaver.c:29: note: previous declaration of 'mapAtoB' was here make: *** [lib/libhaver.o] Error 1 

它适用于9.2但不适用于9.6 ……我做错了什么?

看起来你正在使用“版本0调用约定” 。

应该在9.6中工作,但在PostgreSQL v10中删除了对它的支持。

切换到版本1调用约定:

 PG_FUNCTION_INFO_V1(mapAtoB); Datum mapAtoB(PG_FUNCTION_ARGS) { int32 i = PG_GETARG_INT32(0); int32 a2 = PG_GETARG_INT32(1); int32 a1 = PG_GETARG_INT32(2); PG_RETURN_INT32(i - (a1-a2)); }