为PostgreSQL 9.6编译C函数时出错

时间:2018-07-20 14:21:24

标签: c postgresql

我正在升级到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上工作...我在做什么错??

1 个答案:

答案 0 :(得分:0)

看起来您正在使用“version 0 calling convention”

应该可以在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));
}