Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot link with Lua library on Linux

Tags:

c

linux

gcc

lua

I've compiled Lua 5.2 on Debian x86-64 with make posix, and am trying to compile the following with the command gcc -ldl -llua main.c

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
int main() {  
  lua_State *L = luaL_newstate(); 
  luaL_openlibs(L);  
  dofile("test.lua");   
  return 0;
}

and get unresolved references to the lua functions

like image 246
clem Avatar asked Jun 26 '26 01:06

clem


1 Answers

Assuming your error is

undefined reference to `dofile'

then your problem is that dofile is a lua function and not a C one.

You probably want luaL_dofile(L, "test.lua").

like image 169
Etan Reisner Avatar answered Jun 28 '26 20:06

Etan Reisner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!