Gfortran -static avoids missing DLL errors

Compilers typically have an option to specify static linking of the compiler libraries. This can help mitigate “missing libgfortran” errors, particularly on Windows. This problem arises because the developer may switch compiler environments, or the end user may not have compiler libraries with a compatible ABI installed or on PATH / LD_LIBRARY_PATH. Build environment switching is especially common on Windows, and relatively few Windows users have compilers installed, so missing DLLs have long been a hallmark of distributing Windows programs in various programming languages.

GCC / Gfortran use the -static command line option to statically link the compiler libraries e.g. libgfortran into the final executable. This increases the size of the executable, but the extra space may be negligible compared to the nuisances avoided.

gfortran -static myprog.f90 mylib.f90 -o myprog.exe

Other compilers

clang -static
flang -static-flang-libs
ifort -static-intel


  • We don’t universally apply static linking because some libraries may only be available as dynamic.
  • MacOS static linked executable may only work on your specific computer, it’s not intended for distribution. MacOS prefers dynamic linking.