lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Does anyone have an example of how to compile lua.c for Windows using
> MinGW, with loadlib support (I want some libraries statically linked, and 
> others dynamically linked)? An example of compiling a dynamic library under 
> MinGW would also be desirable..

I assume you are also using MSYS. If not, get it from the mingw site.

Using Lua 5.0.2, I added the following target to the Makefile

# make all with shared libraries (for Win32)
dll:
        cd include; $(MAKE) all
        cd src; $(MAKE) all
        cd src/lib; $(MAKE) all
        rm -f bin/*
        gcc -shared -o bin/lua.dll src/*.o \
                -Wl,--export-all-symbols,--output-def,lib/lua.def,--out-implib,lib/liblua.a
        gcc -shared -o bin/lualib.dll src/lib/*.o -Llib -llua \
                -Wl,--export-all-symbols,--output-def,lib/lualib.def,--out-implib,lib/liblualib.a
        cd src/lua; $(MAKE)
        cd src/luac; $(MAKE)

In the file named "config"
1. uncomment this line:
NUMBER= -DLUA_USER_H='"../etc/luser_number.h"' -DUSE_FASTROUND
2. comment this line:
#EXTRA_LIBS= -lm
3. configure these lines as follows:
USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE
EXTRA_LIBS= -lm -lreadline -lhistory # -lhistory -lcurses -lncurses -ldl 

Now a simple 'make dll' while in the top lua-5.0.2 will build all the
files.

Copy everything in the lua-5.0.2/bin to MSYS/local/bin
and copy liblualib.a and liblua.a to MSYS/local/lib

Now you can compile dynamically loadable libraries by linking them
with liblualib.a and liblua.a (-L /usr/local/lib -llua -llualib).

e