baf <
b...@nowhere.com> writes:
> Strange. I have been using the -static option for some time without
> problems on windows machines. What version of gfortran did you use to
> create the executable?
I tried two different versions of gfortran. Because the target was
32-bit Windows Vista, my first attempt was on a 32-bit Windows XP host
running an experimental build of 4.8.0. Later, after I finally found
the right command line option (-m32), my second attempt was on a 64-bit
Windows 7 host running 4.7.1. In both cases, the command line option
that I used to link in the libraries was -static-libgfortran. In both
cases, the executables did not work on the 32-bit Windows Vista machine,
but the DLL it wanted was different.
Since then, I've done some experimentation. I built four executables
of a program on the 64-bit Windows 7 host:
1: no static options at all
2: -static
3: -static-libgfortran
4: -static and -static-libgfortran
Interestingly, executables 2 and 4 were the exact same size, but
differed in exactly two bytes. Both worked on the 32-bit Windows Vista
machine without any libraries. Executable 1 did not work, as expected,
and executable 3 also didn't work. The main reason for building
executable 1 was so that I could compare file sizes. I also looked at
the file sizes for the corresponding DLLs. As expected, the size of
executable 3 increased compared to executable 1 by almost the size of
the libgfortran DLL, and the sizes of executables 2 and 4 increased
compared to executable 3 by almost the size of the gcc DLL.
So the problem was due to a misunderstanding on my part of the
difference between the -static and -static-libgfortran options.
I had an experience a long time ago in which my memory was that
-static-libgfortran worked, while -static did not, so either my
memory of that event is faulty, or the experiment was corrupted
by the presence of a DLL that I didn't know about, or maybe the
compilers have changed since then. Whatever the case, I now know
that -static is all one needs to generate a standalone executable.
But this experience does raise an interesting question: under what
circumstances would someone want to use -static-libgfortran?
Also, it seems to me that having a single web page that provides
ALL the command line options for gfortran would be useful, rather
than the current practice of having the gfortran-specific options
separate from the gcc-generic options. They could be kept segregated
on the same web page, with clear indications as to which are generic
to the gcc compiler suite and which are specific to gfortran. But
it would simplify searching for the option you need. It took me too
long to find the -m32 option that I needed to generate a 32-bit
executable for the target system on a 64-bit host.