I think “-static” is not being clearly described in this thread ( and I probably can’t do better myself )
Is -static an abbreviation for -static-libgfortran ?
“-static” in this context refers to linking, when the libraries are either “statically” included in the resulting .exe when it is being generated or are dynamically linked with .exe and included when it is “run”.
If the .exe is statically linked, then there is no requirement to have the compiler libraries available (in the path) when you run the program, as the necesary libraries have been included in the .exe.
If the .exe is dynamically linked, then the .dll libraries must also be available when you run the program, as well as when the .exe is built.
Which option you choose depends on what compiler libraries are available when you link the program. It depends on what is installed with the compiler.
For example, I use two gfortran compilers on windows.
equation.com version only provides static libraries and so “-save” is implied.
mingw-w64 version provides dynamic link libraries by default and so the path for the library files must be available when the program is run.
I must admit, I only use the default option with each compiler.
The advantage of dynamic .dll is that the library can be updated without the need of remaking the .exe, although I have rarely utilised this option.
The advantage of -save static build is that the .exe is more easily portable. It can be transferred to other PC without the need to check the libraries are installed and in the path.
In practice, I prefer equation.com’s -save implementation, as you don’t have to keep track of which library version are in the path when you run the program, which can be a problem if you are changing compiler versions. Moving .exe files between pc’s is not as significant an issue, as I usually use -march=native, which also limits .exe portability.
I personally do not see many practical benefits of using dynamic .dll builds, but I am sure there are cases where they are required, especially where third-party static libraries are not available.
The solution to your problem may be to remove -save and use default, unless third-party libraries are required.