Help needed Building static binaries on Windows

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

Help needed Building static binaries on Windows

Stefan Schroeder
Thank you Tim and Milind for your answers.

I am downloading Codeblocks right now to check out the project files you attached.
@Tim: I'd appreciate your further help w/ the compilation.
@Milind: I will try out merging my lua files w/ many2one.

It seems to me that most of the documentation "out there" is Linux or Mac specific...

I will post my results here. Give me a few days.

Regs.
Stefan

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Stefan Schroeder
With the help of Milind's codeblocks project I have been able to
compile srlua and glue,
but not all is good.

How I compile now:

Using srlua-102 as recommended by Luiz Henrique de Figueiredo from
http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/srlua-102.tar.gz

Compiling like this:

mingw:
    mingw32-gcc.exe -Wall -O2 -static-libgcc  -c srglue.c -o glue.o
    mingw32-g++.exe  -o glue.exe glue.o  -s
    mingw32-gcc.exe -Wall -O2 -static-libgcc -I. -I$(LUA_INCDIR) -c
srlua.c -o srlua.o
    mingw32-g++.exe  -o srlua.exe  srlua.o -s $(LUA_DLL) -mwindows
    .\glue.exe .\srlua.exe test.lua out.exe

With test.lua having
  print("hello world")

While it compiles and creates "out.exe", it doesn't work, because
"out.exe" doesn't print anything when run (no error, but also no
hello).

Using TDM-GCC-5.1.0-3 and Lua-5.3.

Regs.
Stefan

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Luiz Henrique de Figueiredo
> While it compiles and creates "out.exe", it doesn't work, because
> "out.exe" doesn't print anything when run (no error, but also no
> hello).

What happens when you run srlua.exe? It should say something like

./srlua.exe: cannot find a Lua program in ./srlua.exe: no glue

Otherwise, try adding this line in main just after lua_State *L:

char name[MAX_PATH]; argv[0]=
GetModuleFileName(NULL,name,sizeof(name)) ? name : NULL

and this line just before the first #include:

#include <windows.h>

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Stefan Schroeder
In reply to this post by Stefan Schroeder
This is what each of the generated executables print when run.
I applied the suggested changes (adding include and name assignment),
but this made no difference.

D:\src\srlua-102>.\glue.exe
usage: .\glue.exe in.exe in.lua out.exe

D:\src\srlua-102>.\srlua.exe

D:\src\srlua-102>.\out.exe

(in other words: Nothing is printed)
I've tried to link against lua5.1dll, lua51.dll, lua53.dll, lua5.3.dll.
When adding a simple printf("Hello"); in main of srlua, this is also
not printed.

Something is severely amiss, but there are too many moving parts to
use trial-and-error to figure it out.

Then I looked up the meaning of "-mwindows"? The GCC manual says that
this is for "GUI applications".
I removed it, and, TA-DAH, it works, even after reverting the changes
suggested by Luiz.

Thanks everybody for your help. I will def. come back later, because I
have the gut feeling that using srlua for a complex
application will be much harder than a trivial one.

@Luiz: Do you mind if I provide a patch for the Makefile of srlua-102?

thx

Am Mo., 25. Nov. 2019 um 13:00 Uhr schrieb <[hidden email]>:

>
> Date: Mon, 25 Nov 2019 08:15:05 -0300
> From: Luiz Henrique de Figueiredo <[hidden email]>
> Subject: Re: Help needed Building static binaries on Windows
> To: Lua mailing list <[hidden email]>
> Message-ID:
>         <[hidden email]>
> Content-Type: text/plain; charset="UTF-8"
>
> > While it compiles and creates "out.exe", it doesn't work, because
> > "out.exe" doesn't print anything when run (no error, but also no
> > hello).
>
> What happens when you run srlua.exe? It should say something like
>
> ./srlua.exe: cannot find a Lua program in ./srlua.exe: no glue
>
> Otherwise, try adding this line in main just after lua_State *L:
>
> char name[MAX_PATH]; argv[0]=
> GetModuleFileName(NULL,name,sizeof(name)) ? name : NULL
>
> and this line just before the first #include:
>
> #include <windows.h>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Luiz Henrique de Figueiredo
> I removed it, and, TA-DAH, it works, even after reverting the changes
> suggested by Luiz.

So, just to make it clear, srlua-102 works fine unchanged?

> @Luiz: Do you mind if I provide a patch for the Makefile of srlua-102?

Yes, please it to me. Thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Ulrich Schmidt
In reply to this post by Stefan Schroeder
You may want to take a look at

https://github.com/Fuzzlix/luaRUN

As you are using gcc, you can use the Makefile. Simply adjust the fileld
inside

the "user settings" section of the makefile.

Ulrich.

Am 25.11.2019 um 11:12 schrieb Stefan Schroeder:

> With the help of Milind's codeblocks project I have been able to
> compile srlua and glue,
> but not all is good.
>
> How I compile now:
>
> Using srlua-102 as recommended by Luiz Henrique de Figueiredo from
> http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/srlua-102.tar.gz
>
> Compiling like this:
>
> mingw:
>      mingw32-gcc.exe -Wall -O2 -static-libgcc  -c srglue.c -o glue.o
>      mingw32-g++.exe  -o glue.exe glue.o  -s
>      mingw32-gcc.exe -Wall -O2 -static-libgcc -I. -I$(LUA_INCDIR) -c
> srlua.c -o srlua.o
>      mingw32-g++.exe  -o srlua.exe  srlua.o -s $(LUA_DLL) -mwindows
>      .\glue.exe .\srlua.exe test.lua out.exe
>
> With test.lua having
>    print("hello world")
>
> While it compiles and creates "out.exe", it doesn't work, because
> "out.exe" doesn't print anything when run (no error, but also no
> hello).
>
> Using TDM-GCC-5.1.0-3 and Lua-5.3.
>
> Regs.
> Stefan
>

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

aryajur
In reply to this post by Stefan Schroeder
Hi Stefan,
          When you told me you wanted to do a IUP application I sent you the srlua compile project for GUI applications. When you compile with that the console things don't work (I don't know why). For console applications compile srlua using this code blocks configuration:

Let me know if that works for you now.

Milind

On Mon, Nov 25, 2019 at 2:12 AM Stefan Schroeder <[hidden email]> wrote:
With the help of Milind's codeblocks project I have been able to
compile srlua and glue,
but not all is good.

How I compile now:

Using srlua-102 as recommended by Luiz Henrique de Figueiredo from
http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/srlua-102.tar.gz

Compiling like this:

mingw:
    mingw32-gcc.exe -Wall -O2 -static-libgcc  -c srglue.c -o glue.o
    mingw32-g++.exe  -o glue.exe glue.o  -s
    mingw32-gcc.exe -Wall -O2 -static-libgcc -I. -I$(LUA_INCDIR) -c
srlua.c -o srlua.o
    mingw32-g++.exe  -o srlua.exe  srlua.o -s $(LUA_DLL) -mwindows
    .\glue.exe .\srlua.exe test.lua out.exe

With test.lua having
  print("hello world")

While it compiles and creates "out.exe", it doesn't work, because
"out.exe" doesn't print anything when run (no error, but also no
hello).

Using TDM-GCC-5.1.0-3 and Lua-5.3.

Regs.
Stefan


srluaCmd.cbp (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

aryajur
Also this configuration you can use it for GUI applications as well but the graphics sometimes look bit different and old. For GUI applications you can choose a Manifest for windows to make the graphics look updated. So that was the reason I prepared a separate project for GUI applications for selection icons and manifests.

On Mon, Nov 25, 2019 at 5:04 PM Milind Gupta <[hidden email]> wrote:
Hi Stefan,
          When you told me you wanted to do a IUP application I sent you the srlua compile project for GUI applications. When you compile with that the console things don't work (I don't know why). For console applications compile srlua using this code blocks configuration:

Let me know if that works for you now.

Milind

On Mon, Nov 25, 2019 at 2:12 AM Stefan Schroeder <[hidden email]> wrote:
With the help of Milind's codeblocks project I have been able to
compile srlua and glue,
but not all is good.

How I compile now:

Using srlua-102 as recommended by Luiz Henrique de Figueiredo from
http://webserver2.tecgraf.puc-rio.br/~lhf/ftp/lua/ar/srlua-102.tar.gz

Compiling like this:

mingw:
    mingw32-gcc.exe -Wall -O2 -static-libgcc  -c srglue.c -o glue.o
    mingw32-g++.exe  -o glue.exe glue.o  -s
    mingw32-gcc.exe -Wall -O2 -static-libgcc -I. -I$(LUA_INCDIR) -c
srlua.c -o srlua.o
    mingw32-g++.exe  -o srlua.exe  srlua.o -s $(LUA_DLL) -mwindows
    .\glue.exe .\srlua.exe test.lua out.exe

With test.lua having
  print("hello world")

While it compiles and creates "out.exe", it doesn't work, because
"out.exe" doesn't print anything when run (no error, but also no
hello).

Using TDM-GCC-5.1.0-3 and Lua-5.3.

Regs.
Stefan

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Stefan Schroeder
In reply to this post by Stefan Schroeder
I can now confirm that srlua-102 compiles and runs as designed on
Windows using this additional Makefile and with no change to the
sources.

The file below successfully runs with mingw32-make on the cmd-shell
and also with plain 'make -f Makefile.mingw' in the Cygwin-terminal.
I can now create my binaries for Windows as desired. Tested with the
versions that I noted down on the Wiki-page:
https://lua-users.org/wiki/BuildingLuaInWindowsForNewbies at the
bottom.

Next steps could be:
(1) Adding a Windows-resources file (for the icon and some metadata
with windres);
(2) compile statically to avoid the need to copy all the DLLs.
(3) Generating an NSIS-installer configuration to pack my app in an installer.

(->1) has been done by some srlua-forks on Github.
(->2) I am going to investigate with low priority
(->3) Should be pretty straightforward. Have done it before. (if 3 is
done, 2 becomes less important).

I say, it's really great what you can do with Lua. It's so incredibly versatile.

## Makefile.mingw
# Makefile for srlua for mingw32, to be run in Windows-cmd shell.
# Contributed to srlua by Stefan Schroeder under the same license
# conditions that srlua is published under.
#

# Change this setting to meet your configuration:
LUA_TOPDIR= d:/Lua/5.1
# Depending on your Lua-distro, the dll might also be located
# elsewhere:
LUA_DLL=$(LUA_TOPDIR)/lib/lua5.1.dll
# Everything below this line should be ok.
LUA_INCDIR= $(LUA_TOPDIR)/include
LUA_LIBDIR= $(LUA_TOPDIR)/lib

CC=mingw32-gcc -std=c99 -Wall -O2
CXX=mingw32-g++.exe

all: check bin test

check:
ifneq ("$(wildcard $(LUA_DLL))","")
    @echo "Lua-DLL was found. You are good to go."
else
    $(error Lua-DLL was NOT found. Cannot continue. Please fix LUA_DLL")
endif

bin:
    $(CC) -static-libgcc  -c srglue.c -o glue.o
    $(CXX) -o glue.exe glue.o  -s
    $(CC) -static-libgcc -I. -I$(LUA_INCDIR) -c srlua.c -o srlua.o
    $(CXX) -o srlua.exe  srlua.o -s $(LUA_DLL)

# The 'test' target patches the PATH temporarily, so that the DLL
# is in the PATH.
test:
    ./glue.exe ./srlua.exe test.lua out.exe
    cmd /c "SET PATH=%PATH%;$(LUA_LIBDIR)&out.exe 123 abc"

.PHONY: all bin test

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Ką Mykolas
Pretty much unrelated note, but something must be done about the following:
This server could not prove that it is lua-users.org; its security
certificate is from pepperfish.net.
This may be caused by a misconfiguration or an attacker intercepting
your connection.

On Thu, Nov 28, 2019 at 1:10 PM Stefan Schroeder <[hidden email]> wrote:
>
> versions that I noted down on the Wiki-page:
> https://lua-users.org/wiki/BuildingLuaInWindowsForNewbies at the
> bottom.
>

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Luiz Henrique de Figueiredo
> This server could not prove that it is lua-users.org; its security
> certificate is from pepperfish.net.
> This may be caused by a misconfiguration or an attacker intercepting
> your connection.

This works: http://lua-users.org/wiki/BuildingLuaInWindowsForNewbies

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Rob Kendrick-2
In reply to this post by Ką Mykolas
On Thu, Nov 28, 2019 at 02:58:06PM +0200, Ką Mykolas wrote:
> Pretty much unrelated note, but something must be done about the following:
> This server could not prove that it is lua-users.org; its security
> certificate is from pepperfish.net.
> This may be caused by a misconfiguration or an attacker intercepting
> your connection.

lua-users.org has never been accessible via HTTPS - you may be using
something such as HTTPS Anywhere that is incorrectly configured if you
see this error.

B.

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Ką Mykolas
Well, I just clicked the link You have posted, which do include https ;)

On Thu, Nov 28, 2019 at 3:27 PM Rob Kendrick <[hidden email]> wrote:

>
> On Thu, Nov 28, 2019 at 02:58:06PM +0200, Ką Mykolas wrote:
> > Pretty much unrelated note, but something must be done about the following:
> > This server could not prove that it is lua-users.org; its security
> > certificate is from pepperfish.net.
> > This may be caused by a misconfiguration or an attacker intercepting
> > your connection.
>
> lua-users.org has never been accessible via HTTPS - you may be using
> something such as HTTPS Anywhere that is incorrectly configured if you
> see this error.
>
> B.
>

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Rob Kendrick-2
On Thu, Nov 28, 2019 at 03:29:32PM +0200, Ką Mykolas wrote:
> Well, I just clicked the link You have posted, which do include https ;)

I posted no link :)  This issue is common when a website does not have
HTTPS but the server does: the web server has no certificate to offer
that matches, so it'll provide the default one.

B.

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Ką Mykolas
Ooops, sorry. That that OP :} Got mixed up in the thread.
In any way, faulty cert sounds worse then no cert at all.

On Thu, Nov 28, 2019 at 3:43 PM Rob Kendrick <[hidden email]> wrote:

>
> On Thu, Nov 28, 2019 at 03:29:32PM +0200, Ką Mykolas wrote:
> > Well, I just clicked the link You have posted, which do include https ;)
>
> I posted no link :)  This issue is common when a website does not have
> HTTPS but the server does: the web server has no certificate to offer
> that matches, so it'll provide the default one.
>
> B.
>

Reply | Threaded
Open this post in threaded view
|

Re: Help needed Building static binaries on Windows

Rob Kendrick-2
On Thu, Nov 28, 2019 at 04:03:50PM +0200, Ką Mykolas wrote:
> Ooops, sorry. That that OP :} Got mixed up in the thread.
> In any way, faulty cert sounds worse then no cert at all.

Nothing wrong with the certificate, what is wrong is the URL you
followed.

B.