[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- 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).
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:
/tmp/ccWw87j6.o: In function `main':
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:
#include <stdio.h>
#include <string.h>
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
int main(int argc, char *argv[])
{
char buff[256];
int error;
lua_State *L;
L = lua_open();
lua_openlibs(L);
while(fgets(buff, sizeof(buff), stdin) != NULL)
{
printf("hi");
error = luaL_loadbuffer(L, buff, strlen(buff), "line") ||
lua_pcall(L, 0, 0, 0);
if (error)
#include <lualib.h>
{
fprintf(stderr, "%s", lua_tostring(L, -1));
lua_pop(L, 1);
}
}
lua_close(L);
return 0;
}
Thanks,
-Patrick Donnelly
"One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say."
-Will Durant