0

我正在尝试构建 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 库吗?

4

2 回答 2

1

这个错误:

rowstamp.h:26:2:警告:函数“HeapTupleHeaderGetXmin”的隐式声明 [-Wimplicit-function-declaration]

强烈建议您针对不同的 PostgreSQL 版本进行编译,而不是您尝试编译的 PL/Lua 源。也许扩展没有维护并且是旧的 PostgreSQL 版本?或者您可能正在尝试针对 9.3 为 PostgreSQL 9.4 编译一个版本?

更新:

HeapTupleHeaderGetXmin37484ad2aacef5ec794f4dd3d5cf814475180a78根据git blame src/include/access/htup_details.h和在提交中引入git log -SHeapTupleHeaderGetXmin。该提交首先出现在master分支的历史记录中 - 它不存在于REL9_3_STABLE. 所以是的,看起来您尝试编译的 PL/Lua 是最新未发布的 PostgreSQL 的版本。

您应该能够下载 9.3 的 PL/Lua 并编译它而不会出现问题。

于 2014-05-26T11:17:30.517 回答
1

解决 !

首先按照建议(感谢 Craig Ringer)我从 postgrsql 9.3 迁移到 postgres 9.2

其次,当您在 /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 -shared -o pllua.so pllua.o plluaapi.o plluaspi.o -L/opt/PostgreSQL/9.2/lib -L/opt/local/20140108/fc7f8f12-7861-11e3-aaff-000c29d23b02/lib  -L/usr/local/lib -Wl,--as-needed -Wl,-rpath,'/opt/PostgreSQL/9.2/lib',--enable-new-dtags  -L/opt/myLua/lib -llua 

链接器无法识别位于/opt/myLua/lib 中的共享库 liblua.so,这就像选项 -L/opt/myLua/lib -llua 不起作用(可能是 Makefile 问题)

所以我将 liblua.so 移到 /usr/local/lib 中执行了 ldconfig,现在可以了:

root@lua:/opt/PostgreSQL/9.2/lib/postgresql# ldd -v pllua.so 
    linux-vdso.so.1 =>  (0x00007fff3eddb000)
    liblua.so => /usr/local/lib/liblua.so (0x00007f2884eb1000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2884aeb000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f28847e4000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f28845e0000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f28843ca000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f2885337000)

    Version information:
    ./pllua.so:
        libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
    /usr/local/lib/liblua.so:
        libdl.so.2 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libdl.so.2
        ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
        libgcc_s.so.1 (GCC_3.3) => /lib/x86_64-linux-gnu/libgcc_s.so.1
        libgcc_s.so.1 (GCC_3.0) => /lib/x86_64-linux-gnu/libgcc_s.so.1
        libm.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libm.so.6
        libc.so.6 (GLIBC_2.3.4) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.4) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.7) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
    /lib/x86_64-linux-gnu/libc.so.6:
        ld-linux-x86-64.so.2 (GLIBC_2.3) => /lib64/ld-linux-x86-64.so.2
        ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
    /lib/x86_64-linux-gnu/libm.so.6:
        libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
    /lib/x86_64-linux-gnu/libdl.so.2:
        ld-linux-x86-64.so.2 (GLIBC_PRIVATE) => /lib64/ld-linux-x86-64.so.2
        libc.so.6 (GLIBC_PRIVATE) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6
    /lib/x86_64-linux-gnu/libgcc_s.so.1:
        libc.so.6 (GLIBC_2.14) => /lib/x86_64-linux-gnu/libc.so.6
        libc.so.6 (GLIBC_2.2.5) => /lib/x86_64-linux-gnu/libc.so.6

您现在如何看到 pllua 与正确的 liblua.so 链接: liblua.so => /usr/local/lib/liblua.so (0x00007f2884eb1000)

之后,我使用 PgAdminIII 加载了模块并测试了在http://pllua.projects.pgfoundry.org/找到的示例

于 2014-06-03T08:12:45.400 回答