DLLs with MinGW

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

DLLs with MinGW

marcus.cf
I was trying to compile Lua 5 as DLLs with MinGW (from 
Dev-C++) to be used in Delphi and C.
The main issues were:
- Windows XP shell, which was unable to execute the 
makefiles
- Discover the precise options I would need (hunt 
makefiles, config, build and the wiki)
- I wanted to learn how to do it by hand, without 
makefiles...

Finally I compiled Lua as follows. If anyone spots an 
error, please tell me. So far, it seems to work. I guess 
I should put it on the wiki if it's correct.

set CFLAGS=-O2 -Wall -
DLUA_USER_H="\"../etc/luser_number.h\"" -DUSE_FASTROUND

cd src

gcc %CFLAGS% -I..\include -c *.c

cd lib

set PIPE=-DUSE_POPEN=1 -Dpopen=_popen -Dpclose=_pclose

gcc %CFLAGS% %PIPE% -I..\..\include -c *.c

cd ..\..

gcc -shared -Wl,--export-all-symbols -o bin\lua-5.0.dll 
src\*.o

gcc -shared -Wl,--export-all-symbols -o bin\lualib-
5.0.dll src\lib\*.o bin\lua-5.0.dll

gcc %CFLAGS% -o bin\lua.exe -Iinclude -D_POSIX_SOURCE 
src\lua\lua.c bin\lualib-5.0.dll bin\lua-5.0.dll

gcc %CFLAGS% -o src\luac\lopcodes.o -Iinclude -
DLUA_OPNAMES -c src\lopcodes.c

gcc %CFLAGS% -o bin\luac.exe -Iinclude -Isrc 
src\luac\luac.c src\luac\print.c src\luac\lopcodes.o 
bin\lualib-5.0.dll bin\lua-5.0.dll

The examples I found on the wiki were much more complex, 
I feel I may be missing something...

 
__________________________________________________________________________
Seleção de Softwares UOL.
10 softwares escolhidos pelo UOL para você e sua família.
http://www.uol.com.br/selecao



Reply | Threaded
Open this post in threaded view
|

Re: DLLs with MinGW

Ignacio Castaño
Marcus, you just have to install MSYS or cygwin. If you don't want anything
fancy, download MSYS, it is very small and provides the basic build
environment, so that you just have to type 'make'.


Ignacio Castaño
[hidden email]


marcus.cf wrote:
I was trying to compile Lua 5 as DLLs with MinGW (from
Dev-C++) to be used in Delphi and C.
The main issues were:
- Windows XP shell, which was unable to execute the
makefiles
- Discover the precise options I would need (hunt
makefiles, config, build and the wiki)
- I wanted to learn how to do it by hand, without
makefiles...

Finally I compiled Lua as follows. If anyone spots an
error, please tell me. So far, it seems to work. I guess
I should put it on the wiki if it's correct.

set CFLAGS=-O2 -Wall -
DLUA_USER_H="\"../etc/luser_number.h\"" -DUSE_FASTROUND

cd src

gcc %CFLAGS% -I..\include -c *.c

cd lib

set PIPE=-DUSE_POPEN=1 -Dpopen=_popen -Dpclose=_pclose

gcc %CFLAGS% %PIPE% -I..\..\include -c *.c

cd ..\..

gcc -shared -Wl,--export-all-symbols -o bin\lua-5.0.dll
src\*.o

gcc -shared -Wl,--export-all-symbols -o bin\lualib-
5.0.dll src\lib\*.o bin\lua-5.0.dll

gcc %CFLAGS% -o bin\lua.exe -Iinclude -D_POSIX_SOURCE
src\lua\lua.c bin\lualib-5.0.dll bin\lua-5.0.dll

gcc %CFLAGS% -o src\luac\lopcodes.o -Iinclude -
DLUA_OPNAMES -c src\lopcodes.c

gcc %CFLAGS% -o bin\luac.exe -Iinclude -Isrc
src\luac\luac.c src\luac\print.c src\luac\lopcodes.o
bin\lualib-5.0.dll bin\lua-5.0.dll

The examples I found on the wiki were much more complex,
I feel I may be missing something...


__________________________________________________________________________
Seleção de Softwares UOL.
10 softwares escolhidos pelo UOL para você e sua família.
http://www.uol.com.br/selecao



Reply | Threaded
Open this post in threaded view
|

Re: DLLs with MinGW

Jilani Khaldi-3
Marcus, you just have to install MSYS or cygwin. If you don't want anything
fancy, download MSYS, it is very small and provides the basic build
environment, so that you just have to type 'make'.
Ignacio,
I downloaded MSYS and I did just what you told, but I get this error when I try to do "make". What's the trouble?
Do I have to modify the "config" file?
//
jilani@DENEB /lua
$ make
cd include; make all
make[1]: Entering directory `/lua/include'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/lua/include'
cd src; make all
make[1]: Entering directory `/lua/src'
gcc -O2 -Wall -I../include      -c -o lapi.o lapi.c
gcc.exe: installation problem, cannot exec `cpp': No such file or directory
make[1]: *** [lapi.o] Error 1
make[1]: Leaving directory `/lua/src'
make: *** [all] Error 2

jilani@DENEB /lua
$ //
Thanks.

jilani



Reply | Threaded
Open this post in threaded view
|

Re: DLLs with MinGW

marcus.cf
In reply to this post by marcus.cf
I didn't know MSYS, and Cygwin was too big. Thanks for 
the tip.
Anyway, the standard makefiles don't have a target "dll"
(it's not much different from "so", but it's not the 
same)

Jilani's error is an instalation problem (as the message 
said: couldn't exec the C-pre-processor). I don't know 
what could have caused that, but you should try to 
compile a "hello world" program and see if it works.

> > Marcus, you just have to install MSYS or cygwin. If y
ou don't want 
> > anything
> > fancy, download MSYS, it is very small and provides t
he basic build
> > environment, so that you just have to type 'make'.
> Ignacio,
> I downloaded MSYS and I did just what you told, but I g
et this error when I 
> try to do "make". What's the trouble?
> Do I have to modify the "config" file?
> //
> jilani@DENEB /lua
> $ make
> cd include; make all
> make[1]: Entering directory `/lua/include'
> make[1]: Nothing to be done for `all'.
> make[1]: Leaving directory `/lua/include'
> cd src; make all
> make[1]: Entering directory `/lua/src'
> gcc -O2 -Wall -I../include      -c -o lapi.o lapi.c
> gcc.exe: installation problem, cannot exec `cpp': No su
ch file or directory
> make[1]: *** [lapi.o] Error 1
> make[1]: Leaving directory `/lua/src'
> make: *** [all] Error 2
> 
> jilani@DENEB /lua
> $ //
> Thanks.
> 
> jilani

 
__________________________________________________________________________
Seleção de Softwares UOL.
10 softwares escolhidos pelo UOL para você e sua família.
http://www.uol.com.br/selecao



Reply | Threaded
Open this post in threaded view
|

Re: DLLs with MinGW

Ignacio Castaño
marcus.cf wrote:
> I didn't know MSYS, and Cygwin was too big. Thanks for
> the tip.
> Anyway, the standard makefiles don't have a target "dll"
> (it's not much different from "so", but it's not the
> same)

To build the dlls you will need a rule like this:

dll:
DLLWRAP --output-def lib/liblua.def --implib lib/liblua.dll.a src/*.o
$(DLLWRAP_OPTS) -o bin/lua-$V.dll
DLLWRAP --output-def lib/liblualib.def --implib lib/liblualib.dll.a
src/lib/*.o $(DLLWRAP_OPTS) -L$(LIB) -llua.dll -o bin/lualib-$V.dll

where DLLWRAP and DLLWRAP_OPTS are:

DLLWRAP=dllwrap.exe
DLLWRAP_OPTS= --no-export-all-symbols --add-stdcall-alias

you also have define LUA_API as '__declspec(dllexport)'

The loadmodule library does that, and also add support for loadable binary
modules:

http://lua-users.org/wiki/LuaBinaryModules
http://talika.eii.us.es/~titan/lua/lua-5.0-loadmodule-2002-12-18.patch

Hope that helps,


Ignacio Castaño
[hidden email]



Reply | Threaded
Open this post in threaded view
|

Re: DLLs with MinGW

marcus.cf
In reply to this post by marcus.cf
> To build the dlls you will need a rule like this:
> 
> dll:
> DLLWRAP --output-def lib/liblua.def
> --implib lib/liblua.dll.a src/*.o
> $(DLLWRAP_OPTS) -o bin/lua-$V.dll
> DLLWRAP --output-def lib/liblualib.def --
implib lib/liblualib.dll.a
> src/lib/*.o $(DLLWRAP_OPTS) -L$(LIB) -llua.dll -
o bin/lualib-$V.dll
> 
> where DLLWRAP and DLLWRAP_OPTS are:
> 
> DLLWRAP=dllwrap.exe
> DLLWRAP_OPTS= --no-export-all-symbols
> --add-stdcall-alias
> 
> you also have define LUA_API as '__declspec(dllexport)'
> 

But what I wanted to know is whether my batch file was 
correct. It works with C and Delphi (doing only basic 
tests), but there may be hidden gotchas. I used --export-
all-symbols and didn't define LUA_API because luac needs 
internal functions. I didn't use --output-def, --implib 
and --add-stdcall-alias either.

> The loadmodule library does that, and also add support 
for loadable binary
> modules:
> 
> http://lua-users.org/wiki/LuaBinaryModules
> http://talika.eii.us.es/~titan/lua/lua-5.0-loadmodule-
2002-12-18.patch

Is loadmodule's purpose similar to loadlib's?

> Hope that helps,
> 
> 
> Ignacio Castaño
> [hidden email]

 
__________________________________________________________________________
Seleção de Softwares UOL.
10 softwares escolhidos pelo UOL para você e sua família.
http://www.uol.com.br/selecao