I am attempting to embed lua code in C++, and I'm getting a strange compiler error. Here's my code:
#include <stdio.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
int main() {
lua_State *luaVM = luaL_newstate();
if (luaVM == NULL) {
printf("Error initializing lua!\n");
return -1;
}
luaL_openlibs(luaVM);
luaL_dofile(luaVM, "test.lua");
lua_close(luaVM);
return 0;
}
compiled with:
g++ -Wall -o embed -llua embed.cpp
and the error is:
g++ -Wall -o embed -llua embed.cpp
/tmp/ccMGuzal.o: In function `main':
embed.cpp:(.text+0x47): undefined reference to `luaL_loadfilex'
embed.cpp:(.text+0x72): undefined reference to `lua_pcallk'
collect2: error: ld returned 1 exit status
I am not calling luaL_loadfilex
or lua_pcallk
from my code, which lends itself to the assumption that the problem is not in my code, but in lua itself. does anyone have any ideas here?
UPDATE
Here is my version info:
$ lua -v
Lua 5.2.0 Copyright (C) 1994-2011 Lua.org, PUC-Rio