[Mingw-users] Stand Alone Executable for GFortran

Back to archive index
Pete Linden pete_linde****@att*****
Wed Jul 1 22:37:01 JST 2020


On Install 1,
The date on libgfortran-3.dll is May 2017

I use code Blocks and it generates the following to perform a rebuild

mingw32-gfortran.exe -Jobj\Debug\ -Wall  -ffree-line-length-none -ffixed-line-length-none -g     -c C:\DATA\FOR95\RRVWSP\main.f95 -o obj\Debug\main.o
mingw32-gfortran.exe  -o bin\Debug\RRVWSP.exe obj\Debug\main.o   c:\dislin\dismg.a -luser32 -lgdi32 -lopengl32 -lgcc
Output file is bin\Debug\RRVWSP.exe with size 895.68 KB
Process terminated with status 0 (0 minute(s), 3 second(s))
0 error(s), 0 warning(s) (0 minute(s), 3 second(s))

I added static to the link options in Code Blocks and it added -lgcc to the link options.  This allowed the executable to "standalone".  This means to me that I can execute it without using the compiler.

On Install 2,
The date on libgfortran-5.dll is Oct 2019

I use code Blocks and it generates the following to perform a rebuild

mingw32-gfortran.exe -Jobj\Debug\ -Wall  -ffree-line-length-none -ffixed-line-length-none -g     -c C:\DATA\FOR95\RRVWSP\MAIN.f95 -o obj\Debug\MAIN.o
mingw32-gfortran.exe  -o bin\Debug\RRVWSP.exe obj\Debug\MAIN.o   c:\dislin\dismg.a -luser32 -lgdi32 -lopengl32 -lgcc c:\dislin\dismg.a -luser32 -lgdi32 -lopengl32
Output file is bin\Debug\RRVWSP.exe with size 895.68 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))

When I first contacted you I was using static added to the Code Block linker.  Code Blocks complained about the use of static.  I then added libgcc to the linker options in Code Blocks. Now Code Blocks adds -lgcc to the linker options.  This now generates a standalone executable.  

My conclusion is that my original problem had nothing to do with how MinGW was installed.  The problem was the linker options.

What do you think?

Peter N. Linden, P.E.
Linden Professional Services, Inc.
9103 Brahms Lane
Houston, Texas 77040
Direct – 713-937-7875
Cell – 713-253-3216

-----Original Message-----
From: MinGW-Users [mailto:mingw****@lists*****] On Behalf Of Keith Marshall
Sent: Tuesday, June 30, 2020 5:24 PM
To: MinGW Users List
Subject: Re: [Mingw-users] Stand Alone Executable for GFortran

On 30/06/2020 01:09, James McGroder wrote:
> On 6/29/20 1:44 PM, Pete Linden wrote:
>> I have two installs of Mingw and GFortran.  On the 1st one I can make 
>> a Stand Alone Executable using GFortran. On the 2nd one, I can not 
>> make a Stand Alone Executable for GFortran.
>>
>> Did I make an install error?
>>
> Hard to say... 

No, it's actually _impossible_ to answer this effectively, because the original question is completely devoid of essential detail.  Pete, will you please read, and inwardly digest in its entirety:
http://catb.org/~esr/faqs/smart-questions.html

> Please share gfortran & shell command line(s) for Stand-alone and and
> *NON* Stand-alone examples.

Yes, both of those are essential; also, we need to be told _exactly_ which packages, and their respective versions, comprise each of the two installations in question.

> A Stand-Alone example could be something like this:
> 
> jim at OptiPlex-780 ~/src $gfortran hello.f
>  *** without -o option, a.out is default output
> jim at OptiPlex-780 ~/src $./a.out
> Hello World

And, as an example, even this is totally inadequate; where is the source code, from which such an example might be compiled?  Furthermore, the default output file is a.exe ... _not_ a.out, (which is a Unixism).

> On Non stand-alone, I'm inferring you mean something with subroutines...
> So how are they linked?

And again, source is imperative.

> Or are you working libraries?

Given how appallingly bad the original question is, I'm reluctant to offer _any_ sort of answer, but as a wild, and entirely speculative guess, I'd incline toward this; default linking mode for gfortran pulls in libgfortran-5.dll, together with libgcc_s_dw2-1.dll, both of which must thus be distributed along with any dependent application, so rendering that application non-stand-alone:

  $ cat foo.f
        program hello
          print *, "Hello World!"
          end

  $ mingw32-gfortran foo.f
  $ mingw32-ldd a.exe
  a.exe
   +- KERNEL32.dll
   +- msvcrt.dll
   +- msvcrt.dll
   +- libgcc_s_dw2-1.dll
   |   +- KERNEL32.dll
   |   +- msvcrt.dll
   +- libgfortran-5.dll

Note that the above was cross-compiled, on my GNU/Linux box, hence the "mingw32-" prefix to commands; the dependency on libgfortran-5.dll is clearly evident, as is a further dependency on libgcc_s_dw2-1.dll

If my wild guess is correct, and this is the OP's issue, then both of those dependencies may be eliminated, by compiling with "-static":

  $ mingw32-gfortran -static foo.f
  $ mingw32-ldd a.exe
  a.exe
   +- ADVAPI32.DLL
   +- KERNEL32.dll
   +- msvcrt.dll
   +- msvcrt.dll

The remaining dependencies are all standard MS-Windows system DLLs, so in this case, a.exe becomes effectively self-contained.

If my wild guess is incorrect, then I'm sorry, but no one can offer a better answer until the question is asked more appropriately.

--
Regards,
Keith.

Public key available from keys.gnupg.net Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F



More information about the MinGW-Users mailing list
Back to archive index