0

I'm trying to use gcc to dynamically link to the lua library but I keep getting undefined references to every single lua function, including luaL_newstate.

Here's the code I'm trying to compile

#include <stdlib.h>

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>

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

And here's the command I'm using

cls && gcc test.c -Ilua-5.4.2_Win64_dllw6_lib\include -Llua-5.4.2_Win64_dllw6_lib -llua54

I also tried static linking with -l:liblua54.a, changing the order of the parameters, and moving the files into the mingw64 include and lib folders and using those instead, but nothing seems to change anything.

7
  • 1
    Is that the only message you get? When asking questions about build error, always please include the full and complete build log (as it might contain other information that could be helpful). Please edit your question to include the copy-pasted (as text) build log. Commented Aug 13, 2022 at 7:26
  • That's all I'm getting. It just gives me undefined references to the two lua functions and then exits with the collect2.exe error as usual. Adding more functions increases the undefined references but there are no other errors.
    – fungi986
    Commented Aug 13, 2022 at 7:58
  • Are you sure that the given path of option "-L" points from the current directory to the directory the library exists? Commented Aug 13, 2022 at 21:30
  • Yes, otherwise it wouldn't even be able to find the headers as the include folder is in that same folder. If the folder was invalid it would return a "cannot find -llua54" error instead.
    – fungi986
    Commented Aug 13, 2022 at 21:39
  • Are you trying to build a 32-bit binary but linking against a 64-bit Lua library, or vice versa? Commented Aug 13, 2022 at 23:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.