[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Compiling/Executing problems in C
- From: Patrick Donnelly <batrick@...>
- Date: Mon, 9 Jul 2007 12:54:09 -0600
I'm trying to play around with Lua in C, and have been unable to get a Lua interpreter to compile (the build your own one in PIL: http://www.lua.org/pil/24.1.html)./tmp/ccWw87j6.o: In function `main':
I'm using Ubuntu linux, and when I try doing `gcc mytest.c` (mytest.c being what I called the program), I get the following errors:
mytest.c:(.text+0x2b): undefined reference to `luaL_newstate'
mytest.c:(.text+0x3f): undefined reference to `lua_openlibs'
mytest.c:(.text+0x9a): undefined reference to `luaL_loadbuffer'
mytest.c:(.text+0xc4): undefined reference to `lua_pcall'
mytest.c:(.text+0x117): undefined reference to `lua_tolstring'
mytest.c:(.text+0x139): undefined reference to `lua_settop'
mytest.c:(.text+0x16e): undefined reference to `lua_close'
collect2: ld returned 1 exit status
I think this is a linking issue so I looked at LuaSocket's make file (actually the config file) for guidance. I instead used `gcc mytest.c -shared`. That compiles ok. But when I run the program I get a segmentation fault. I even removed every statement in main() except "return 0;" and I still get a segmentation fault. Does anyone know what I'm doing wrong here?
Here's mytest.c if you want to look at it:
int main(int argc, char *argv)
L = lua_open();
while(fgets(buff, sizeof(buff), stdin) != NULL)
error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
lua_pcall(L, 0, 0, 0);
fprintf(stderr, "%s", lua_tostring(L, -1));
"One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say."