c - 为 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));
}
推荐阅读
- javascript - 如何将nodejs请求路由到另一个nodejs应用程序?
- python - docker compose up generate (2005, "Unknown MySQL server host 'db' (-2)") 错误
- php - 为什么此查询不会从所有表中删除详细信息?
- android - 如何在 Windows 上同时打开多个 Android Studio 实例或同一项目但不同分支的实例?
- node.js - 我如何在节点 js 中将通知应用程序发送到 web 我是 nodejs 的新手,如果可以的话
- ios - 通过 SecCertificate 从证书中检索颁发者名称
- android - 如何使用数据绑定将 ProgressBar 可见性与 ImageView 绑定
- java - 无法处理 mustUnderstand 标头:{http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}安全。返回故障
- nginx - nginx 缓存:仅当上游服务器不可访问时才返回缓存页面(当给出特定的 Cache-Control 标头时)
- docker - 如何在我的 docker 容器启动时设置我的私有 ssh_key 的正确权限?