为什么 Lua 报告说 lua_pushlstring 未定义?

我已经成功编译了Lua 5.1.4用于Palm webOS,现在我正在尝试编写一个扩展,使用Lua来调用webOS的服务。但是,当我尝试加载我的库时,Lua报告:

undefined symbol: lua_pushlstring

这是我的代码:

#define LUA_LIB
#include "lua.h"
#include "lauxlib.h"

static int hellopalm(lua_State *L) {
    lua_pushliteral(L, "Hello, Palm!");
    return 1;
}

static const luaL_reg palmlib[] = {
    { "hellopalm", hellopalm },
    { NULL, NULL }
};

LUALIB_API int luaopen_palm(lua_State *L) {
    luaL_register(L, "palm", palmlib);
    return 1;
}

这是我的Makefile:

LUADIR= ../lua-5.1.4/lua-webos
CC= arm-none-linux-gnueabi-gcc
CFLAGS= -O2 -Wall -shared -nostdlib -mcpu=arm1136jf-s -mfpu=vfp -mfloat-abi=softfp
INCLUDES= -I$(LUADIR)/include
RM= rm -f

LIBNAME= palmlib.so
SOURCES= palmlib.c

default: $(LIBNAME)

clean:
    $(RM) $(LIBNAME)

$(LIBNAME): palmlib.c
    $(CC) $(CFLAGS) $(INCLUDES) $(SOURCES) -o $@

我知道lua_pushliteral只是调用lua_pushlstring的宏,因此错误来自于此。但似乎所有的push_ *变种都不起作用,请问是我的Makefile出了问题吗?

有什么想法吗?

原文链接 https://stackoverflow.com/questions/3107102

点赞
stackoverflow用户107090
stackoverflow用户107090

你需要在构建 Lua 解释器时导出 Lua API 符号。在 Linux 上,gcc 的标志为 -Wl,-E;也许这在你的平台上也适用。

2010-06-24 07:20:01