0

I want to make so that I can call lua functions from my C program but I dont know how to load the lua library.

So far I have tried to download all the lua source code from lua.org, and then put them into the same folder as my C program. And then included them in the C code.

How my code looks now:

#include "lua.h"
#include "lauxlib.h"

int main()
{
    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    luaL_dofile(L, "test.lua");
    return 0;
}

Error msg when compiling:

test.c: In function ‘main’: test.c:10:5: warning: implicit declaration of function ‘luaL_openlibs’ [->Wimplicit-function-declaration] luaL_openlibs(L); ^ In file included from test.c:5:0: lauxlib.h:122:24: warning: value computed is not used [-Wunused-value] (luaL_loadfile(L, fn) || lua_pcall(L, 0, LUA_MULTRET, 0)) ^ test.c:11:5: note: in expansion of macro ‘luaL_dofile’ luaL_dofile(L, "test.lua"); ^ /tmp/ccHJTAY8.o: In function main': test.c:(.text+0x9): undefined reference toluaL_newstate' test.c:(.text+0x1e): undefined reference to luaL_openlibs' test.c:(.text+0x34): undefined reference toluaL_loadfilex' test.c:(.text+0x5f): undefined reference to `lua_pcallk' collect2: error: ld returned 1 exit status

kuken
  • 9
  • 2
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Colonel Thirty Two Nov 02 '15 at 18:03
  • You need to link with the Lua library. What Lua version/platform/compiler are you using? Look here for more info: http://stackoverflow.com/questions/4150081/cannot-link-a-minimal-lua-program – Adam Nov 02 '15 at 18:16
  • lua 5.3.1, windows 7 and gcc – kuken Nov 02 '15 at 19:21
  • 1
    Have you built and installed Lua from source following the "Build Lua" instructions provided here? http://www.lua.org/manual/5.3/readme.html – Adam Nov 02 '15 at 19:44
  • No I havent, didnt know it was necessary – kuken Nov 03 '15 at 15:15

0 Answers0