views:

37

answers:

2

I managed to compile Lua 5.1.4 for Palm webOS and now I'm trying to write an extension to use webOS' services from Lua. However, when I try to load my library, Lua reports:

undefined symbol: lua_pushlstring

Here's my code:

#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;
}

Here's my 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 $@

I know lua_pushliteral is just a macro that calls lua_pushlstring, so that's where the error is coming from. None of the push_* variants seem to work at all. I suspect something is wrong with my Makefile.

Any ideas?

A: 

Are you linking against lua binaries?

Duracell
I tried linking with liblua, yeah. But that didn't change anything.
David Brown
+2  A: 

You need to export the Lua API symbols when you build your Lua interpreter. In Linux, the flags for gcc are -Wl,-E; perhaps this works in your platform as well.

lhf
WebOS is based on Linux, so that did the trick! Thanks!
David Brown
Just so we know: when building Lua, does `make linux` work out of the box in WebOS?
lhf