I need advice on setup compiler for c library with embedded lua in Cygwin with Mingw on Windows

63 Views Asked by At

I am learning how to create a c library with embedded Lua. Sounds simple with everyone but I stuck at compiling the code. Please points me to what I did wrong in follow steps. The important key is I need to use MinGW-w64 toolchain, this is the reason I use Cygwin.

  1. First I install lua and liblua-dev in Cygwin. I chose version 5.3.6-4. From Cygwin, I can run lua script.lua which print a string on the Cygwin terminal.

    print('Hi from script.lua!')

  2. Then I install MinGW-w64 toolchain and add "C:\msys64\ucrt64\bin" to the user environment variables. From Cygwin, I can test the gcc version work correctly.

    $ cc --version cc.exe (Rev3, Built by MSYS2 project) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

I create a doscript.c file as below

#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"

int main(){
    lua_State *L = luaL_newstate();
    luaL_openlibs(L);
    luaL_dofile(L, "script.lua");
    lua_close(L);
    return 0;
}

When I ran command to compile, I got below error

$ cc doscript.c -o doscript -llua
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64
-mingw32/bin/ld.exe: cannot find -llua: No such file or directory
collect2.exe: error: ld returned 1 exit status

From Cygwin if I list the usr/lib, I can see the liblua5.3.dll.a

$ ls /usr/lib
charset.alias  engines-3  liblua-5.3.dll.a  ossl-modules      pkgconfig
csih           gawk       liblua.dll.a      p11-kit-proxy.so  sasl2_3
engines-1.0    groff      liblua5.3.dll.a   perl5             security
engines-1.1    libcbor.a  lua               pkcs11            terminfo

I also tried with the actual library name but still get error

$ cc doscript.c -o doscript -L/usr/lib -llua-5.3.dll
C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64
-mingw32/bin/ld.exe: cannot find -llua-5.3.dll: No such file or directory
collect2.exe: error: ld returned 1 exit status

Is there anything else I should try? Thank you in advance!

0

There are 0 best solutions below