Hi everyone, I found this code that embeds Lua in C, and I can't figure out how to get GCC to compile it. I installed Lua, but how do I link the Lua libraries?
Here is the code I found:
#include <stdio.h>
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
lua_State* l;
int main () {
int dofile;
l = lua_open();
luaL_openlibs(l);
dofile = luaL_dofile(l, "hello.lua");
if (dofile == 0) {
lua_getglobal(l,"foo");
lua_call(l,0,0);
}
else {
printf("Error, unable to run hello.lua\n");
}
lua_close(l);
return 0;
}
How to do this for compilation?
I am trying to execute this command to compile
gcc -o embed_hello -L/users/etrosclair/Downloads/lua-5.1.4 -I/users/etrosclair/Downloads/lua-5.1.4 luaTest.c
Here is the error:
Undefined symbols for architecture x86_64:
"_luaL_newstate", referenced from:
_main in ccF0995Q.o
"_luaL_openlibs", referenced from:
_main in ccF0995Q.o
"_luaL_loadfile", referenced from:
_main in ccF0995Q.o
"_lua_pcall", referenced from:
_main in ccF0995Q.o
"_lua_getfield", referenced from:
_main in ccF0995Q.o
"_lua_call", referenced from:
_main in ccF0995Q.o
"_lua_close", referenced from:
_main in ccF0995Q.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
All lua libraries and headers are in the lua-5.1.4 folder, there are also .o files there.
thank
thank
source
share