- 论坛徽章:
- 0
|
编译官方文档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.)
该怎么处理,请高手帮忙。 |
|