lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Sun, Jun 28, 2009 at 6:44 PM, František Fuka<> wrote:

> Although I am rather proficient in Lua, I am not proficient in C compiling
> and linking. I downloaded the Lua sources from the official site and then I
> tried the example from page 219 in PiL book:

> Then I tried compiling this with "gcc -I../lib/lua-5.1.4/src main.c -o
> emulator" and got the following errors:
> main.c: In function ‘main’:
> main.c:12: warning: incompatible implicit declaration of built-in function
> ‘strlen’
> /tmp/ccsb4CUD.o: In function `main':
> main.c:(.text+0x21): undefined reference to `luaL_newstate'
> main.c:(.text+0x35): undefined reference to `luaL_openlibs'
> main.c:(.text+0x6c): undefined reference to `luaL_loadbuffer'
> main.c:(.text+0x96): undefined reference to `lua_pcall'
> main.c:(.text+0xe9): undefined reference to `lua_tolstring'
> main.c:(.text+0x10b): undefined reference to `lua_settop'
> main.c:(.text+0x140): undefined reference to `lua_close'
> collect2: ld returned 1 exit status
> Now, I am not sure if this is some deeper problem or if I made some very
> basic mistake (again, I don't understand C compiling very much, I do most of
> my stuff in pure Lua) but it seems to me those "undefined" symbols are
> defined in ".h" files in lua-5.1.4/src/ directory.

They are *declared* in the .h files, yes. But the actual compiled code
from the Lua .c files (which is what the linker needs to link all the
compiled code together into the executable) is in
lua-5.1.4/src/liblua.a. Add this to the command-line and you should be
fine :)

> Could you please enlighten me what command line options to create
> stand-alone executable from the example at page 219 using only the original
> Lua sources (not any pre-compiled libraries, it must be completely
> self-sufficient). Thank you very much.

Based on your email, try this: gcc -I../lib/lua-5.1.4/src
../lib/lua-5.1.4/src/liblua.a main.c -o emulator

Hope this helps,