免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3944 | 回复: 1
打印 上一主题 下一主题

postgresql下C语言扩展函数出现错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-02-24 22:55 |只看该作者 |倒序浏览
编译官方文档31.7.3例子:
源代码如下:
#include "postgres.h"
#include <string.h>

/* 传递数值 */

int
add_one(int arg)
{
    return arg + 1;
}
其余的去掉了。存储文funs.c文件,编译为funs.so文件

使用如下语句定义PostgreSQL 函数时出错:

CREATE FUNCTION add_one(integer) RETURNS integer
     AS '/usr/local/pgsql/lib/funs.so', 'add_one'
     LANGUAGE C STRICT;

错误:
ERROR:  incompatible library "/usr/local/pgsql/lib/func.so": missing magic block
HINT:  Extension libraries are required to use the PG_MODULE_MAGIC macro.

postgresql 8.2.3
red hat tenterprise linux 4

官方8.2.3文档提示如下:
To ensure that a dynamically loaded object file is not loaded into an incompatible server, PostgreSQL
checks that the file contains a “magic block” with the appropriate contents. This allows the server to
detect obvious incompatibilities, such as code compiled for a different major version of PostgreSQL. A
magic block is required as of PostgreSQL 8.2. To include a magic block, write this in one (and only one)
of the module source files, after having included the header fmgr.h:
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
The #ifdef test can be omitted if the code doesn’t need to compile against pre-8.2 PostgreSQL releases.
After it is used for the first time, a dynamically loaded object file is retained in memory. Future calls in the
same session to the function(s) in that file will only incur the small overhead of a symbol table lookup. If
you need to force a reload of an object file, for example after recompiling it, use the LOAD command or
begin a fresh session.
Optionally, a dynamically loaded file can contain initialization and finalization functions. If the file includes
a function named _PG_init, that function will be called immediately after loading the file. The
function receives no parameters and should return void. If the file includes a function named _PG_fini,
that function will be called immediately before unloading the file. Likewise, the function receives no parameters
and should return void. Note that _PG_fini will only be called during an unload of the file, not
during process termination. (Presently, an unload only happens in the context of re-loading the file due to
an explicit LOAD command.)

该怎么处理,请高手帮忙。

论坛徽章:
0
2 [报告]
发表于 2007-03-22 22:34 |只看该作者

回复 1楼 m_lm 的帖子

fmgr.h加入如下语句
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
从新编译安装,ok。问题解决了
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP