无法在Windows版本上获取示例C函数
v9.6,win server 2012,vs 2015 已成功编译并链接为x64 创建函数失败,表示dll中没有“添加一个”函数无法在Windows版本上获取示例C函数,windows,postgresql,Windows,Postgresql,v9.6,win server 2012,vs 2015 已成功编译并链接为x64 创建函数失败,表示dll中没有“添加一个”函数 postgres=# create function add_one(integer) returns integer as 'win32project1',' add_one' language c strict; ERROR: could not find function "add_one" in file "C:/Program Files/Postg
postgres=# create function add_one(integer) returns integer as
'win32project1',' add_one' language c strict;
ERROR: could not find function "add_one" in file "C:/Program Files/PostgreSQL/9.6/lib/win32project1.dll"
dumpbin说,功能似乎就在那里
好的,每个函数需要导出两个函数,元数据函数
pg_finfo_xxx
加上实际函数本身xxx
pg函数编译的标准头使用PGDLLEXPORT标记元数据函数,但实际函数的前向声明没有这样标记。我不明白这是怎么回事
#define PG_FUNCTION_INFO_V1(funcname) \
Datum funcname(PG_FUNCTION_ARGS); \
extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
const Pg_finfo_record * \
CppConcat(pg_finfo_,funcname) (void) \
{ \
static const Pg_finfo_record my_finfo = { 1 }; \
return &my_finfo; \
} \
extern int no_such_variable
但我是通过这样做才成功的
#define PG_FUNCTION_INFO_V1(funcname) \
PGDLLEXPORT Datum funcname(PG_FUNCTION_ARGS); \
extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
const Pg_finfo_record * \
CppConcat(pg_finfo_,funcname) (void) \
{ \
static const Pg_finfo_record my_finfo = { 1 }; \
return &my_finfo; \
} \
extern int no_such_variable
您没有显示源文件,但它应该包含以下内容:
extern PGDLLEXPORT Datum add_one(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(add_one);
那么它可能会起作用
我已经开始在PostgreSQL中实现,但是似乎PostgreSQL正在使用的构建过程(生成和使用导出定义文件)至少会引起警告,所以我们已经放弃了
另一个选项是像PostgreSQL一样创建和使用导出定义文件,然后可以完全不使用PGDLLEXPORT装饰。我直接从9.6文档页面复制了源文件,但它确实有效,但是如果PG_函数_INFO中有PGDLLEXPORT,那么就不需要这个额外的行。文档中的示例似乎不是针对Windows的。那是个错误。我将提出一个补丁。接下来看看黑客们对此有何评论。叹气——“到目前为止还没有人抱怨。当我们在做的时候,让我们确保它在windows上不起作用。”
extern PGDLLEXPORT Datum add_one(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(add_one);