I'm trying to compile a c++ program that uses lua in gcc and am getting this compile error when I use g++ main.cpp -o test
"main.cpp:27: error: ‘lua_dofile’ was not declared in this scope" any idea on what I'm doing wrong?
extern "C"
{
#include <lua5.1/lua.h>
//these includes are in the correct directory
#include <lua5.1/lualib.h>
#include <lua5.1/lauxlib.h>
}
//include the lua libraries. If your compiler doesn't support this pragma
//then don't forget to add the libraries in your project settings!
#pragma comment(lib, "lua.lib")
#pragma comment(lib, "lualib.lib")
#include <iostream>
int main()
{
//create a lua state
lua_State* pL = lua_open();
//enable access to the standard libraries
luaopen_base(pL);
luaopen_string(pL);
luaopen_table(pL);
luaopen_math(pL);
luaopen_io(pL);
if (int error = lua_dofile(pL, "your_first_lua_script.lua") != 0)
{
std::cout << "\n[C++]: ERROR(" << error << "): Problem with lua script file!\n\n" << std::endl;
return 0;
}
//tidy up
lua_close(pL);
return 0;
}
as far as I know I'm using the correct libs, I tried "g++ main.cpp -llua5.1 -llualib" and got the same error message. I've searched in /usr/lib/ and those seem like the only lua libs.
Randi wrote:as far as I know I'm using the correct libs, I tried "g++ main.cpp -llua5.1 -llualib" and got the same error message. I've searched in /usr/lib/ and those seem like the only lua libs.
Thanks for the help, that worked but then I had a runtime error "PANIC: unprotected error in call to Lua API (no calling environment)". I'll post the solution for anyone else who is new at this. I needed to replace anything that had luaopen_ in front of it with " luaL_openlibs (pL);". The working code: