[Mingw-users] Stand Alone Executable for GFortran

Back to archive index
Keith Marshall keith****@users*****
Wed Jul 1 07:23:48 JST 2020

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:

> 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!"

  $ mingw32-gfortran foo.f
  $ mingw32-ldd 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
   +- 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.


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.osdn.me/mailman/archives/mingw-users/attachments/20200630/80e725f5/attachment.sig>

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