我正在尝试构建 pllua 模块,但遇到了一些麻烦。
我认为问题出在错误的 PostgreSQL 版本上,但我不确定,如果有人可以帮助我,我将不胜感激。
Postgres 位置:/opt/PostgreSQL/9.3/bin (是enterpriceb版本,不支持)
Lua 位置:/opt/myLua(使用 luaDist 构建)
root@lua:/opt/BootstrapLuaDist/LuaDist/bin# ./luadist /opt/myLua/ list
Installed modules:
==================
bit32-5.2.0 (Ubuntu-x86_64) [provided by luajit-2.0.3]
lua-5.1.5 (Ubuntu-x86_64) [provided by luajit-2.0.3]
luaffi-1.0 (Ubuntu-x86_64) [provided by luajit-2.0.3]
luafilesystem-1.6.2 (Ubuntu-x86_64)
luajit-2.0.3 (Ubuntu-x86_64)
luasocket-3.0-rc1 (Ubuntu-x86_64)
srlua-5.1 (Ubuntu-x86_64)
zlib-1.2.6 (Ubuntu-x86_64)
我已经修改了 pllua makefile:
# Makefile for PL/Lua
# $Id: Makefile,v 1.12 2009/09/20 14:20:48 carvalho Exp $
# Lua specific
# General
#LUAINC = -I/usr/local/include
#LUALIB = -L/usr/local/lib -llua
# LuaJIT
#LUAINC = -I/usr/local/include/luajit-2.0
#LUALIB = -L/usr/local/lib -lluajit-5.1
#myLuaJit 2.0.3
LUAINC= -I/opt/myLua/include
LUALIB = -L/op/myLua/lib -lliblua
# Debian/Ubuntu
#LUAINC = -I/usr/include/lua5.1
#LUALIB = -llua5.1
# Fink
#LUAINC = -I/sw/include -I/sw/include/postgresql
#LUALIB = -L/sw/lib -llua
# Lua for Windows
#LUAINC = -IC:/PROGRA~1/Lua/5.1/include
#LUALIB = -LC:/PROGRA~1/Lua/5.1/lib -llua5.1
# no need to edit below here
MODULE_big = pllua
EXTENSION = pllua
DATA = pllua--1.0.sql
#DATA_built = pllua.sql
REGRESS = plluatest
OBJS = pllua.o plluaapi.o plluaspi.o
PG_CPPFLAGS = $(LUAINC)
SHLIB_LINK = $(LUALIB)
#PG_CONFIG = /usr/local/pgsql/bin/pg_config
PG_CONFIG = /opt/PostgreSQL/9.3/bin/pg_config
#PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
但是编译会产生错误和警告:
root@lua:/opt/pllua-1.0# make
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I/opt/myLua/include -I. -I. -I/opt/PostgreSQL/9.3/include/postgresql/server -I/opt/PostgreSQL/9.3/include/postgresql/internal -D_GNU_SOURCE -I/opt/local/20140108/fc7f8f12-7861-11e3-aaff-000c29d23b02/include/libxml2 -I/usr/local/include/libxml2 -I/usr/local/include -c -o pllua.o pllua.c
gcc -O2 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fpic -I/opt/myLua/include -I. -I. -I/opt/PostgreSQL/9.3/include/postgresql/server -I/opt/PostgreSQL/9.3/include/postgresql/internal -D_GNU_SOURCE -I/opt/local/20140108/fc7f8f12-7861-11e3-aaff-000c29d23b02/include/libxml2 -I/usr/local/include/libxml2 -I/usr/local/include -c -o plluaapi.o plluaapi.c
In file included from plluaapi.c:8:0:
rowstamp.h: In function ‘rowstamp_set’:
rowstamp.h:26:2: warning: implicit declaration of function ‘HeapTupleHeaderGetXmin’ [-Wimplicit-function-declaration]
stamp->xmin = HeapTupleHeaderGetXmin(tup->t_data);
^
plluaapi.c: At top level:
plluaapi.c:41:3: error: unknown type name ‘int2’
int2 len;
^
plluaapi.c: In function ‘luaP_gettypeinfo’:
plluaapi.c:149:5: warning: implicit declaration of function ‘GETSTRUCT’ [-Wimplicit-function-declaration]
typeinfo = (Form_pg_type) GETSTRUCT(type);
^
plluaapi.c:149:16: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
typeinfo = (Form_pg_type) GETSTRUCT(type);
^
plluaapi.c: In function ‘luaP_modinit’:
plluaapi.c:350:11: warning: implicit declaration of function ‘heap_getattr’ [-Wimplicit-function-declaration]
lua_pushstring(L, text2string(heap_getattr(SPI_tuptable->vals[i],
^
plluaapi.c: In function ‘luaP_newfunction’:
plluaapi.c:637:12: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
procst = (Form_pg_proc) GETSTRUCT(proc);
^
plluaapi.c: In function ‘luaP_pusharray’:
plluaapi.c:753:9: warning: implicit declaration of function ‘fetch_att’ [-Wimplicit-function-declaration]
luaP_pushdatum(L, fetch_att(*p, ti->byval, ti->len), typeelem);
^
plluaapi.c:755:9: warning: implicit declaration of function ‘att_addlength_pointer’ [-Wimplicit-function-declaration]
*p = att_addlength_pointer(*p, ti->len, *p);
^
plluaapi.c:755:12: warning: assignment makes pointer from integer without a cast [enabled by default]
*p = att_addlength_pointer(*p, ti->len, *p);
^
plluaapi.c:756:9: warning: implicit declaration of function ‘att_align_nominal’ [-Wimplicit-function-declaration]
*p = (char *) att_align_nominal(*p, ti->align);
^
plluaapi.c:756:14: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
*p = (char *) att_align_nominal(*p, ti->align);
^
plluaapi.c: In function ‘luaP_toarray’:
plluaapi.c:954:13: warning: implicit declaration of function ‘store_att_byval’ [-Wimplicit-function-declaration]
store_att_byval(*p, PointerGetDatum(v), ti->len);
^
plluaapi.c: In function ‘luaP_todatum’:
plluaapi.c:1047:15: warning: implicit declaration of function ‘heap_form_tuple’ [-Wimplicit-function-declaration]
dat = PointerGetDatum(SPI_returntuple(heap_form_tuple(ti->tupdesc,
^
plluaapi.c:1047:15: warning: passing argument 1 of ‘SPI_returntuple’ makes pointer from integer without a cast [enabled by default]
In file included from pllua.h:18:0,
from plluaapi.c:7:
/opt/PostgreSQL/9.3/include/postgresql/server/executor/spi.h:113:24: note: expected ‘HeapTuple’ but argument is of type ‘int’
extern HeapTupleHeader SPI_returntuple(HeapTuple tuple, TupleDesc tupdesc);
^
make: *** [plluaapi.o] Error 1
非常感谢
### - 更新 - -我解决了(仅部分)这个问题。从 enterpriceb 下载 postgreSQL 9.2,现在编译正常,pllua.so 安装在 /opt/PostgreSQL/9.2/lib/postgresql 中。
当我运行时: root@lua:/opt/PostgreSQL/9.2/bin# ./psql -U postgres -p 5435 -c "CREATE EXTENSION pllua" postgres
它引发了一个错误:
错误:无法加载库“/opt/PostgreSQL/9.2/lib/postgresql/pllua.so”:/opt/PostgreSQL/9.2/lib/postgresql/pllua.so:未定义符号:luaopen_math
现在 luaopen_math 有什么问题?可能我需要在编译之前加载一些 luaJit 库吗?