[Solved] using Lua 5.1.4 in c++ [/Solved]
Posted: Sat Apr 24, 2010 1:39 pm
I am trying to compile a c++ program that uses lua. The compiler I am using mingw, under ubuntu.
In console I type "g++ -o test main.cpp -llua -ldl". This returns:
foo.lua is as follows:
main.cpp is as follows
In console I type "g++ -o test main.cpp -llua -ldl". This returns:
Code: Select all
main.cpp:3:17: error: lua.h: No such file or directory
main.cpp:4:20: error: lualib.h: No such file or directory
main.cpp:5:21: error: lauxlib.h: No such file or directory
main.cpp: In function ‘int main()’:
main.cpp:10: error: ‘lua_State’ was not declared in this scope
main.cpp:10: error: ‘L’ was not declared in this scope
main.cpp:10: error: ‘lua_open’ was not declared in this scope
main.cpp:11: error: ‘luaL_openlibs’ was not declared in this scope
main.cpp:12: error: ‘luaL_dofile’ was not declared in this scope
main.cpp:13: error: ‘printf’ was not declared in this scope
main.cpp:14: error: ‘lua_close’ was not declared in this scope
Code: Select all
#!/usr/bin/lua
io.write("Please enter your name: ")
name = io.read() -- read input from user
print ("Hi " .. name .. ", enjoy hacking with Lua");
Code: Select all
extern "C"
{
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
int main()
{
int s = 0;
lua_State *L = lua_open();
luaL_openlibs(L);
luaL_dofile(L,"foo.lua");
printf("\nI am done with Lua in c++\n");
lua_close(L);
return 0;
}