- 論壇徽章:
- 0
|
編譯官方文檔31.7.3例子:
源代碼如下:
#include "postgres.h"
#include <string.h>
/* 傳遞數(shù)值 */
int
add_one(int arg)
{
return arg + 1;
}
其余的去掉了。存儲(chǔ)文funs.c文件,編譯為funs.so文件
使用如下語句定義PostgreSQL 函數(shù)時(shí)出錯(cuò):
CREATE FUNCTION add_one(integer) RETURNS integer
AS '/usr/local/pgsql/lib/funs.so', 'add_one'
LANGUAGE C STRICT;
錯(cuò)誤:
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.)
該怎么處理,請(qǐng)高手幫忙。 |
|