0

I am try to use Lua 5.3.3 scripting in my c++ project, I am compiling with gcc, code::blocks. I get errors when I try to use Lua functions, such as newstate().

main.cpp:

#include <lua/lua.hpp>
// ...

int main()
{
    lua_State *state = luaL_newstate();
    lua_close(state);
    // ...
    return 0;
}

errors:

||=== Build: Debug in MettaRPG (compiler: GNU GCC Compiler) ===| obj\Debug\src\main.o||In function 'main':| C:\Users\user\Documents\Coding\CodeBlocks\MettaRPG\src\main.cpp|12|undefined reference to 'luaL_newstate'| C:\Users\user\Documents\Coding\CodeBlocks\MettaRPG\src\main.cpp|13|undefined reference to 'lua_close'| ||error: ld returned 1 exit status| ||=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

possible duplicates:

"Undefined reference to" using Lua Did not solve my problem when I tried it. It yielded the same errors.

Lua 5.3 undefined references I am using this in my program, but it still doesn't work.

Building Lua for C++ Also doens't fix my problem.

Community
  • 1
  • 1
Melkor
  • 779
  • 1
  • 12
  • 29
  • That's a linker error, most likely because you aren't linking the lua library properly. – Retired Ninja Nov 27 '16 at 19:38
  • I have managed to fix the issue. I hadn't correctly included Lua. I resolved this by installing a prebuilt **dynamic** library, putting the *.c* and *.h* files in include, and the *.a* files in the lib file, the *.dll* files in the project's main directory. I had to go to build settings and link in the include and library folder. Download the prebuilt library from here: http://lua-users.org/wiki/LuaBinaries – Melkor Nov 28 '16 at 17:18

0 Answers0