GFORTRAN(1)
β¨ NAME β¨
okay so this is the gfortran(1) page from the GNU manual, and it's literally the GNU Fortran compiler, bestie π no cap.
gfortran β GNU Fortran compiler π«Ά
π SYNOPSIS π
gfortran [-c|-S|-E]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...]
[-mmachine-option...]
[-o outfile] infile...
Only the most useful options are listed here; see below for the remainder. β like, these are just the VIPs, the rest are down below, periodt.
π DESCRIPTION π
so the gfortran command supports all the options supported by the gcc command. Only options specific to GNU Fortran are documented here, bestie.
All GCC and GNU Fortran options are accepted both by gfortran and by gcc (as well as any other drivers built at the same time, such as g++), since adding GNU Fortran to the GCC distribution enables acceptance of GNU Fortran options by all of the relevant drivers. it's giving "every driver is in on the Fortran options" energy, fr fr.
In some cases, options have positive and negative forms; the negative form of -ffoo would be -fno-foo. This manual documents only one of these two forms, whichever one is not the default. so if you see one, just know the other one is lurking, iykyk.
π OPTIONS π
Here is a summary of all the options specific to GNU Fortran, grouped by type. Explanations are in the following sections. β okay bestie, here's the tea, all the options by category, explanations below π
Fortran Language Options
-fall-intrinsics-fallow-argument-mismatch-fallow-invalid-boz-fbackslash-fcray-pointer-fd-lines-as-code-fd-lines-as-comments-fdec-fdec-char-conversions-fdec-structure-fdec-intrinsic-ints-fdec-static-fdec-math-fdec-include-fdec-format-defaults-fdec-blank-format-item-fdefault-double-8-fdefault-integer-8-fdefault-real-8-fdefault-real-10-fdefault-real-16-fdollar-ok-ffixed-line-length-n-ffixed-line-length-none-fpad-source-ffree-form-ffree-line-length-n-ffree-line-length-none-fimplicit-none-finteger-4-integer-8-fmax-identifier-length-fmodule-private-ffixed-form-fno-range-check-fopenacc-fopenmp-fopenmp-allocators-fopenmp-simd-freal-4-real-10-freal-4-real-16-freal-4-real-8-freal-8-real-10-freal-8-real-16-freal-8-real-4-std=std-ftest-forall-temp-funsigned
Preprocessing Options
-A-question[=answer]-Aquestion=answer-C-CC-Dmacro[=defn]-H-P-Umacro-cpp-dD-dI-dM-dN-dU-fworking-directory-imultilib dir-iprefix file-iquote-isysroot dir-isystem dir-nocpp-nostdinc-undef
Error and Warning Options
-Waliasing-Wall-Wampersand-Warray-bounds-Wc-binding-type-Wcharacter-truncation-Wconversion-Wdo-subscript-Wfunction-elimination-Wimplicit-interface-Wimplicit-procedure-Wintrinsic-shadow-Wuse-without-only-Wintrinsics-std-Wline-truncation-Wno-align-commons-Wno-overwrite-recursive-Wno-tabs-Wreal-q-constant-Wsurprising-Wunderflow-Wunused-parameter-Wrealloc-lhs-Wrealloc-lhs-all-Wfrontend-loop-interchange-Wtarget-lifetime-fmax-errors=n-fsyntax-only-pedantic-pedantic-errors
Debugging Options
-fbacktrace-fdebug-aux-vars-ffpe-trap=list-ffpe-summary=list
Directory Options
-Idir-Jdir-fintrinsic-modules-path dir
Link Options
-static-libgfortran-static-libquadmath
Runtime Options
-fconvert=conversion-fmax-subrecord-length=length-frecord-marker=length-fsign-zero
Interoperability Options
-fc-prototypes-fc-prototypes-external
Code Generation Options
-faggressive-function-elimination-fblas-matmul-limit=n-fbounds-check-ftail-call-workaround-ftail-call-workaround=n-fcheck-array-temporaries-fcheck=<all|array-temps|bits|bounds|do|mem|pointer|recursion>-fcoarray=<none|single|lib>-fexternal-blas-ff2c-ffrontend-loop-interchange-ffrontend-optimize-finit-character=n-finit-integer=n-finit-local-zero-finit-derived-finit-logical=<true|false>-finit-real=<zero|inf|-inf|nan|snan>-finline-intrinsics[=<minloc,maxloc>]-finline-matmul-limit=n-finline-arg-packing-fmax-array-constructor=n-fmax-stack-var-size=n-fno-align-commons-fno-automatic-fno-protect-parens-fno-underscoring-fsecond-underscore-fpack-derived-frealloc-lhs-frecursive-frepack-arrays-fshort-enums-fstack-arrays
Developer Options
-fdump-fortran-global-fdump-fortran-optimized-fdump-fortran-original-fdump-parse-tree-save-temps
Options controlling Fortran dialect
The following options control the details of the Fortran dialect accepted by the compiler: β like, these are the ones deciding what Fortran flavor the compiler is gonna accept, bestie π
-ffree-form,-ffixed-formβ Specify the layout used by the source file. The free form layout was introduced in Fortran 90. Fixed form was traditionally used in older Fortran programs. When neither option is specified, the source form is determined by the file extension. so free form is the Fortran 90 glow-up, fixed form is the old-school vibe, and if you don't pick one, the file extension chooses for you.-fall-intrinsicsβ This option causes all intrinsic procedures (including the GNU-specific extensions) to be accepted. This can be useful with-std=to force standard compliance but get access to the full range of intrinsics available withgfortran. As a consequence,-Wintrinsics-stdis ignored and no user-defined procedure with the same name as any intrinsic is called except when it is explicitly declared"EXTERNAL". β so it's giving "all the intrinsics, including the GNU exclusives", and it can team up with-std=to keep standard compliance while still getting the full intrinsic menu. but heads up:-Wintrinsics-stdgets ignored, and a user-defined procedure with the same name as an intrinsic won't be called unless it's explicitly declared"EXTERNAL".-fallow-argument-mismatchβ Some code contains calls to external procedures with mismatches between the calls and the procedure definition, or with mismatches between different calls. Such code is nonconforming, and is usually flagged with an error. This options degrades the error to a warning that can only be disabled by disabling all warnings via-w. Only a single occurrence per argument is flagged by this warning.-fallow-argument-mismatchis implied by-std=legacy. β Using this option is strongly discouraged. It is possible to provide standard-conforming code that allows different types of arguments by using an explicit interface andTYPE(*). β okay so this is the "messy code" flag, and it's literally converting an error into a warning that you can only silence by turning off all warnings with-w. only one occurrence per argument gets flagged. it's implied by-std=legacy. but bestie, using this is strongly discouraged, fr fr β you can write standard-conforming code with an explicit interface andTYPE(*)instead.-fallow-invalid-bozβ A BOZ literal constant can occur in a limited number of contexts in standard conforming Fortran. This option degrades an error condition to a warning, and allows a BOZ literal constant to appear where the Fortran standard would otherwise prohibit its use. β so it's letting BOZ literals pop up where the standard says "no ma'am" and downgrading the error to a warning.-fd-lines-as-code,-fd-lines-as-commentsβ Enable special treatment for lines beginning with"d"or"D"in fixed form sources. If the-fd-lines-as-codeoption is given they are treated as if the first column contained a blank. If the-fd-lines-as-commentsoption is given, they are treated as comment lines. β sod/Dlines in fixed form get special treatment: code mode pretends the first column was blank, comments mode treats them as comments.-fdecβ DEC compatibility mode. Enables extensions and other features that mimic the default behavior of older compilers (such as DEC). These features are nonstandard and should be avoided at all costs. For details on GNU Fortran's implementation of these extensions see the full documentation. β Other flags enabled by this switch are:-fdollar-ok-fcray-pointer-fdec-char-conversions-fdec-structure-fdec-intrinsic-ints-fdec-static-fdec-math-fdec-include-fdec-blank-format-item-fdec-format-defaultsβ If-fd-lines-as-code/-fd-lines-as-commentsare unset, then-fdecalso sets-fd-lines-as-comments. β so it's the old-school DEC vibe, nonstandard and should be avoided at all costs. it turns on a whole squad of flags, and if thed-lines flags aren't set, it also sets-fd-lines-as-comments.-fdec-char-conversionsβ Enable the use of character literals in assignments and"DATA"statements for non-character variables. β character literals can be used for non-character variables in assignments and"DATA"statements.-fdec-structureβ Enable DEC"STRUCTURE"and"RECORD"as well as"UNION","MAP", and dot (.) as a member separator (in addition to%). This is provided for compatibility only; Fortran 90 derived types should be used instead where possible. β so DECSTRUCTURE,RECORD,UNION,MAP, and.as a member separator alongside%. compatibility only, bestie; use Fortran 90 derived types if you can.-fdec-intrinsic-intsβ Enable B/I/J/K kind variants of existing integer functions (e.g."BIAND","IIAND","JIAND", etc...). For a complete list of intrinsics see Intrinsic Procedures. β B/I/J/K kind variants of integer functions like"BIAND","IIAND","JIAND", etc. check Intrinsic Procedures for the full list.-fdec-mathβ Obsolete flag. The purpose of this option was to enable legacy math intrinsics such as"COTAN"and degree-valued trigonometric functions (e.g."TAND","ATAND", etc...) for compatibility with older code. This option is no longer operable. The trigonometric functions are now either part of Fortran 2023 or GNU extensions. β so it's obsolete, no longer operable. it used to enable"COTAN"and degree-valued trig like"TAND","ATAND", etc. now those functions are either Fortran 2023 or GNU extensions.-fdec-staticβ Enable DEC-style"STATIC"and"AUTOMATIC"attributes to explicitly specify the storage of variables and other objects. β DEC-style"STATIC"and"AUTOMATIC"attributes for explicit storage specification.-fdec-includeβ Enable parsing of"INCLUDE"as a statement in addition to parsing it as"INCLUDE"line. When parsed as"INCLUDE"statement,"INCLUDE"does not have to be on a single line and can use line continuations. β so"INCLUDE"can be parsed as a statement, not just a line, and it can span multiple lines with continuations.-fdec-format-defaultsβ Enable format specifiers F, G and I to be used without width specifiers; default widths are used instead. β F, G, and I format specifiers can skip width specifiers and use defaults instead.-fdec-blank-format-itemβ Enable a blank format item at the end of a format specification i.e. nothing following the final comma. β blank format item at the end, like nothing after the final comma.-fdollar-okβ Allow$as a valid non-first character in a symbol name. Symbols that start with$are rejected since it is unclear which rules to apply to implicit typing as different vendors implement different rules. Using$in"IMPLICIT"statements is also rejected. β so$is valid as a non-first character in a symbol name. symbols starting with$are rejected because implicit typing rules are a mess across vendors. using$in"IMPLICIT"statements is also rejected.-fbackslashβ Change the interpretation of backslashes in string literals from a single backslash character to"C-style"escape characters. The following combinations are expanded:\a,\b,\f,\n,\r,\t,\v,\\, and\0to the ASCII characters alert, backspace, form feed, newline, carriage return, horizontal tab, vertical tab, backslash, and NUL, respectively. Additionally,\xnn,\unnnnand\Unnnnnnnn(where eachnis a hexadecimal digit) are translated into the Unicode characters corresponding to the specified code points. All other combinations of a character preceded by\are unexpanded. β so backslashes become C-style escapes. here's the expansion table:\aalert,\bbackspace,\fform feed,\nnewline,\rcarriage return,\thorizontal tab,\vvertical tab,\\backslash,\0NUL. plus\xnn,\unnnn,\Unnnnnnnnfor Unicode code points. anything else with\stays unexpanded.-fmodule-privateβ Set the default accessibility of module entities to"PRIVATE". Use-associated entities are not accessible unless they are explicitly declared as"PUBLIC". β default module entity accessibility becomes"PRIVATE", and use-associated entities stay inaccessible unless explicitly"PUBLIC".-ffixed-line-length-nβ Set column after which characters are ignored in typical fixed-form lines in the source file, and, unless"-fno-pad-source", through which spaces are assumed (as if padded to that length) after the ends of short fixed-form lines. β Popular values for n include 72 (the standard and the default), 80 (card image), and 132 (corresponding to"extended-source"options in some popular compilers). n may also be none, meaning that the entire line is meaningful and that continued character constants never have implicit spaces appended to them to fill out the line.-ffixed-line-length-0means the same thing as-ffixed-line-length-none. β so this sets the column cutoff for fixed-form lines, and unless"-fno-pad-source", spaces are assumed up to that length after short lines. popular n values: 72 (standard, default), 80 (card image), 132 (like extended-source in some compilers). n can also be none, meaning the whole line matters and continued character constants don't get implicit trailing spaces.-ffixed-line-length-0=-ffixed-line-length-none.-fno-pad-sourceβ bestie, by default fixed-form lines get spaces assumed after the end of short fixed-form lines, like someone quietly padded them out to that length πΈ. That lil padding does not happen if you're using-ffixed-line-length-0,-ffixed-line-length-none, or this very-fno-pad-sourceoption. And with any of those options, continued character constants never have implicit spaces appended to them to fill out the line. no cap π-ffree-line-length-nβ sets the column after which characters are just ignored in typical free-form lines in the source file π¦. The default is132. Our n can also benone, meaning the entire line is meaningful (main character energy, the whole line matters). And-ffree-line-length-0means the exact same thing as-ffree-line-length-noneβ¨.-fmax-identifier-length=nβ specifies the maximum allowed identifier length π. Typical values are31(Fortran 95) and63(Fortran 2003 and later). pick your era, babe.-fimplicit-noneβ says no implicit typing is allowed, unless an explicitIMPLICITstatement overrides it π. It's literally the equivalent of addingimplicit noneto the start of every procedure. so iconic.-fcray-pointerβ enables the Cray pointer extension, which gives you C-like pointer functionality π₯.-fopenaccβ enables handling of OpenACC directives!$accin free-form Fortran, and!$acc,c$accand*$accin fixed-form Fortran β¨. When-fopenaccis specified, the compiler generates accelerated code according to the OpenACC Application Programming Interface v2.6 (https://www.openacc.org) π. This option implies-pthread, and so it's only supported on targets that have support for-pthread. Also-fopenaccimplies-frecursive. stacking implications, we love to see it π-fopenmpβ enables handling of OpenMP directives!$ompin Fortran π. It additionally enables the conditional compilation sentinel!$in Fortran. And in fixed source form Fortran, those sentinels can also start withcor*. When-fopenmpis specified, the compiler generates parallel code according to the OpenMP Application Program Interface v4.5 (https://www.openmp.org) π₯. This option implies-pthread, so again it's only supported on targets that have support for-pthread. Also-fopenmpimplies-fopenmp-simdand-frecursive. periodt.-fopenmp-allocatorsβ enables handling of allocation, reallocation and deallocation of Fortran allocatable and pointer variables that were allocated using the!$omp allocatorsand!$omp allocateconstructs π«Ά. Files containing either directive have to be compiled with this option in addition to-fopenmp. And not just those files β all files that might deallocate or reallocate a variable that has been allocated with an OpenMP allocator also have to be compiled with this option π. That includes intrinsic assignment to allocatable variables when reallocation may occur, and deallocation due to either of these: end of scope, explicit deallocation,intent(out), deallocation of allocatable components, etc. Now the chill part π: files that don't change the allocation status, or that only touch components of a derived type that have not been allocated using those two directives, do not need this option. Nor do files that handle such variables after they've been deallocated, or after they've been allocated by the normal Fortran allocator. okay so know your scope, girlie.-fopenmp-simdβ enables handling of OpenMP'ssimd,declare simd,declare reduction,assume,ordered,scanandloopdirective, plus combined or composite directives withsimdas a constituent, with!$ompin Fortran β¨. It additionally enables the conditional compilation sentinel!$in Fortran, and in fixed source form Fortran those sentinels can also start withcor*. Other OpenMP directives are ignored π. Unless-fopenmpis additionally specified, theloopregion binds to the current task region, independent of the specifiedbindclause. noted, bestie.-fno-range-checkβ disables range checking on results of simplification of constant expressions during compilation π. For example, GNU Fortran gives an error at compile time when simplifyinga = 1. / 0. With this option, no error is given andais assigned the value+Infinityπ. If an expression evaluates to a value outside of the relevant range of[-HUGE():HUGE()], then the expression is replaced by-Infor+Infas appropriate. Similarly,DATA i/Z'FFFFFFFF'/results in an integer overflow on most systems, but with-fno-range-checkthe value "wraps around" andiis initialized to-1instead. letting math be feral, honestly π-fdefault-integer-8β sets the default integer and logical types to an 8 byte wide type π. This option also affects the kind of integer constants like42. Unlike-finteger-4-integer-8, it does not promote variables with an explicit kind declaration. respectful of boundaries, we love her.-fdefault-real-8β sets the default real type to an 8 byte wide type β¨. This option also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible π₯. If-fdefault-double-8is given along withfdefault-real-8, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-8,fdefault-real-8does not promote variables with explicit kind declarations. again: explicit kind = hands off π-fdefault-real-10β sets the default real type to a 10 byte wide type πΈ. This option also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along with-fdefault-real-10, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-10,fdefault-real-10does not promote variables with explicit kind declarations π.-fdefault-real-16β sets the default real type to a 16 byte wide type π. This option also affects the kind of non-double real constants like1.0. It promotes the default width ofDOUBLE PRECISIONand double real constants like1.d0to 16 bytes if possible. If-fdefault-double-8is given along with-fdefault-real-16, thenDOUBLE PRECISIONand double real constants are not promoted. Unlike-freal-4-real-16,fdefault-real-16does not promote variables with explicit kind declarations β¨.-fdefault-double-8β sets theDOUBLE PRECISIONtype and double real constants like1.d0to an 8 byte wide type π¦. Does nothing if that's already the default, slay. This option prevents-fdefault-real-8,-fdefault-real-10, and-fdefault-real-16from promotingDOUBLE PRECISIONand double real constants like1.d0to 16 bytes. the designated blocker π-finteger-4-integer-8β promotes allINTEGER(KIND=4)entities toINTEGER(KIND=8)entities π. IfKIND=8is unavailable, then an error is issued. β οΈ This option should be used with care and may not be suitable for your codes. Areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O. Inspection of the intermediate representation of the translated Fortran code, produced by-fdump-tree-original, is suggested π.
okay so this one is giving chaos energy β proceed with caution, bestie.
-freal-4-real-8,-freal-4-real-10,-freal-4-real-16,-freal-8-real-4,-freal-8-real-10,-freal-8-real-16β promote allREAL(KIND=M)entities toREAL(KIND=N)entities π . IfREAL(KIND=N)is unavailable, then an error is issued. The-freal-4-flags also affect the default real kind, and the-freal-8-flags also affect the double-precision real kind. All other real-kind types are unaffected by this option. The promotion is also applied to real literal constants of default and double-precision kind and to a specified kind number of4or8, respectively β¨. However,-fdefault-real-8,-fdefault-real-10,-fdefault-real-10, and-fdefault-double-8take precedence for the default and double-precision real kinds β both for real literal constants and for declarations without a kind number π. And note: forREAL(KIND=KIND(1.0))the literal may get promoted and then the result may get promoted again π. double promotion, it's giving glow-up on glow-up. β οΈ These options should be used with care and may not be suitable for your codes. Areas of possible concern include calls to external procedures, alignment inEQUIVALENCEand/orCOMMON, generic interfaces, BOZ literal constant conversion, and I/O and calls to intrinsic procedures when passing a value to thekind=dummy argument. Inspection of the intermediate representation of the translated Fortran code, produced by-fdump-fortran-originalor-fdump-tree-original, is suggested π.- *
-std=std* β specifies the standard the program is expected to conform to, which may be one off95,f2003,f2008,f2018,f2023,gnu, orlegacyπ. The default value for std isgnu, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran β although warnings are given for obsolete extensions not recommended for use in new code πΈ. Thelegacyvalue is equivalent but without the warnings for obsolete extensions, and may be useful for old nonstandard programs. Thef95,f2003,f2008,f2018, andf2023values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008, Fortran 2018 and Fortran 2023 standards, respectively β errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards π. The deprecated option-std=f2008tsacts as an alias for-std=f2018π«. It is only present for backwards compatibility with earlier gfortran versions and should not be used any more, fr fr. And-std=f202yacts as an alias for-std=f2023and enables proposed features for testing Fortran 202y β¨. As the Fortran 202y standard develops, implementation might change or the experimental new features might be removed. so like, experimental = experimental, bestie π. -ftest-forall-tempβ enhances test coverage by forcing mostforallassignments to use a temporary π§ͺ. doing it for the tests.-funsignedβ allows the experimental unsigned extension π¦. yes, experimental, you heard her.
β¨ Enable and customize preprocessing β¨
okay bestie, this is the part where we get to do the fun little code-mixing thing π So many Fortran compilers β GNU Fortran included β will happily run your source code through a C preprocessor (aka CPP; sometimes it's called the Fortran preprocessor, or FPP, same vibe) so you can do conditional compilation. In GNU Fortran's case, it's literally the GNU C Preprocessor, running in traditional mode. π
On systems with case-preserving file names, the preprocessor gets auto-summoned whenever your file extension is .F, .FOR, .FTN, .fpp, .FPP, .F90, .F95, .F03 or .F08. Want to manually drag the preprocessor onto any file? That's -cpp. Want to stop it from running on files where it would normally auto-run? That's -nocpp. Easy. β¨
If a preprocessed file pulls in another file with the Fortran INCLUDE statement, heads up: the included file does not get preprocessed. To preprocess included files, use the equivalent preprocessor statement #include instead. π¦
When GNU Fortran is the one invoking the preprocessor, __GFORTRAN__ is defined. And you can use the macros __GNUC__, __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ to figure out the compiler version. See Top,,Overview,cpp,The C Preprocessor for the deets. π
GNU Fortran also supports a whole bunch of INTEGER and REAL kind types on top of whatever the Fortran standard demands. Whether any given kind type actually exists is architecture dependent β no cap. The following predefined preprocessor macros let you conditionally include code for these extra kind types: __GFC_INT_1__, __GFC_INT_2__, __GFC_INT_8__, __GFC_INT_16__, __GFC_REAL_10__, and __GFC_REAL_16__. π
Now, CPP is the de facto standard for preprocessing Fortran code, but Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines Conditional Compilation, which is not widely used and not directly supported by the GNU Fortran compiler. So like... it exists, it's just not our thing. π
The following options control preprocessing of Fortran code:
-cpp,-nocppβ Enable preprocessing. The preprocessor is automatically invoked if the file extension is.fpp,.FPP,.F,.FOR,.FTN,.F90,.F95,.F03or.F08. Use this option to manually enable preprocessing of any kind of Fortran file. To disable preprocessing of files with any of the above listed extensions, use the negative form:-nocpp. The preprocessor is run in traditional mode. Any restrictions of the file format, especially the limits on line length, apply for preprocessed output as well, so it might be advisable to use the-ffree-line-length-noneor-ffixed-line-length-noneoptions. π‘-dMβ Instead of the normal output, generate a list of#definedirectives for all the macros defined during the execution of the preprocessor, including predefined macros. This gives you a way of finding out what is predefined in your version of the preprocessor. Assuming you have no filefoo.f90, the command
touch foo.f90; gfortran -cpp -E -dM foo.f90
shows all the predefined macros. π
-dDβ Like-dMexcept in two respects: it does not include the predefined macros, and it outputs both the#definedirectives and the result of preprocessing. Both kinds of output go to the standard output file.-dNβ Like-dD, but emit only the macro names, not their expansions.-dUβ LikedDexcept that only macros that are expanded, or whose definedness is tested in preprocessor directives, are output; the output is delayed until the use or test of the macro; and#undefdirectives are also output for macros tested but undefined at the time.-dIβ Output#includedirectives in addition to the result of preprocessing.-fworking-directoryβ Enable generation of linemarkers in the preprocessor output that let the compiler know the current working directory at the time of preprocessing. When this option is enabled, the preprocessor emits, after the initial linemarker, a second linemarker with the current working directory followed by two slashes. GCC uses this directory, when it is present in the preprocessed input, as the directory emitted as the current working directory in some debugging information formats. This option is implicitly enabled if debugging information is enabled, but this can be inhibited with the negated form-fno-working-directory. If the-Pflag is present in the command line, this option has no effect, since no#linedirectives are emitted whatsoever. π-idirafterdir β Search dir for include files, but do it after all directories specified with-Iand the standard system directories have been exhausted. dir is treated as a system include directory. If dir begins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-imultilibdir β Use dir as a subdirectory of the directory containing target-specific C++ headers.-iprefixprefix β Specify prefix as the prefix for subsequent-iwithprefixoptions. If the prefix represents a directory, you should include the final/.-isysrootdir β This option is like the--sysrootoption, but applies only to header files. See the--sysrootoption for more information.-iquotedir β Search dir only for header files requested with#include "file"; they are not searched for#include <file>, before all directories specified by-Iand before the standard system directories. If dir begins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-isystemdir β Search dir for header files, after all directories specified by-Ibut before the standard system directories. Mark it as a system directory, so that it gets the same special treatment as is applied to the standard system directories. If dir begins with=, then the=is replaced by the sysroot prefix; see--sysrootand-isysroot.-nostdincβ Do not search the standard system directories for header files. Only the directories you have specified with-Ioptions (and the directory of the current file, if appropriate) are searched.-undefβ Do not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined.-Apredicate=answer β Make an assertion with the predicate predicate and answer answer. This form is preferred to the older form-A predicate(answer), which is still supported, because it does not use shell special characters.-A-predicate=answer β Cancel an assertion with the predicate predicate and answer answer.-Cβ Do not discard comments. All comments are passed through to the output file, except for comments in processed directives, which are deleted along with the directive. You should be prepared for side effects when using-C; it causes the preprocessor to treat comments as tokens in their own right. For example, comments appearing at the start of what would be a directive line have the effect of turning that line into an ordinary source line, since the first token on the line is no longer a#.
Warning bb: this currently handles C-Style comments only. The preprocessor does not yet recognize Fortran-style comments. π
-CCβ Do not discard comments, including during macro expansion. This is like-C, except that comments contained within macros are also passed through to the output file where the macro is expanded. In addition to the side-effects of the-Coption, the-CCoption causes all C++-style comments inside a macro to be converted to C-style comments. This is to prevent later use of that macro from inadvertently commenting out the remainder of the source line. The-CCoption is generally used to support lint comments.
Warning again: this currently handles C- and C++-Style comments only. The preprocessor does not yet recognize Fortran-style comments. π
-Dname β Predefine name as a macro, with definition1.-Dname=definition β The contents of definition are tokenized and processed as if they appeared during translation phase three in a#definedirective. In particular, the definition is truncated by embedded newline characters. If you are invoking the preprocessor from a shell or shell-like program you may need to use the shell's quoting syntax to protect characters such as spaces that have a meaning in the shell syntax. If you wish to define a function-like macro on the command line, write its argument list with surrounding parentheses before the equals sign (if any). Parentheses are meaningful to most shells, so you need to quote the option. Withshandcsh,-D'name(args...)=definition'works.
-D and -U options are processed in the order they are given on the command line. All -imacros file and -include file options are processed after all -D and -U options. π«Ά
-Hβ Print the name of each header file used, in addition to other normal activities. Each name is indented to show how deep in the#includestack it is.-Pβ Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and is sent to a program that might be confused by the linemarkers.-Uname β Cancel any previous definition of name, either built in or provided with a-Doption.
πΈ Options to request or suppress errors and warnings πΈ
So. Define the terms, bestie, because words matter. π
Errors are diagnostic messages that report that the GNU Fortran compiler cannot compile the relevant piece of source code. The compiler continues to process the program in an attempt to report further errors to aid in debugging, but does not produce any compiled output. Like, it's telling you everything that's wrong before it walks out the door. π
Warnings are diagnostic messages that report constructions that are not inherently erroneous but that are risky or suggest there is likely to be a bug in the program. Unless -Werror is specified, they do not prevent compilation of the program. So warnings are the "hey queen, just so you know π" of the compiler world.
You can request many specific warnings with options beginning -W, for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning -Wno- to turn off warnings; for example, -Wno-implicit. This manual lists only one of the two forms, whichever is not the default. No cap. β¨
These options control the amount and kinds of errors and warnings produced by GNU Fortran:
-fmax-errors=n β Limits the maximum number of error messages to n, at which point GNU Fortran bails out rather than attempting to continue processing the source code. If n is0, there is no limit on the number of error messages produced. π₯-fsyntax-onlyβ bestie this one just does a lil vibe check on your code πΈ it looks for syntax errors and then dips, it does NOT compile anything. The one thing it will spit out is module files for every module in your code, but literally nothing else. No binary, nothing. Just modules and judgment.-Wpedantic,-pedanticβ this one is your code's mean-but-loving older sister π it warns you every time you use a Fortran extension. And-pedanticis extra: it also side-eyes C-language constructs sitting inside your GNU Fortran source files, like using\in a character constant inside a directive like#include.
Okay so, valid Fortran programs should compile just fine with or without this flag, that's the tea. But without it, certain GNU extensions and traditional Fortran features are allowed to slide. With it? Nah, a whole bunch of them get rejected. Periodt.
Real talk though, some people try to use -pedantic to check if their program is fully conforming and... they find out real quick it does not do quite what they want β it catches some nonstandard practices, but lowkey not all of them. Still, if you wanna send in improvements to GNU Fortran in this area, the door is open, king π«Ά
Use this one alongside -std=f95, -std=f2003, -std=f2008, -std=f2018 or -std=f2023. That's the whole squad, you need them together.
-pedantic-errorsβ same energy as-pedantic, except instead of warnings you get full-on errors. It's giving consequences π-Wallβ the classic. This turns on the commonly used warning options that cover usage we recommend you avoid and that we genuinely believe is easy to avoid. Right now that includes-Waliasing,-Wampersand,-Wconversion,-Wsurprising,-Wc-binding-type,-Wintrinsics-std,-Wtabs,-Wintrinsic-shadow,-Wline-truncation,-Wtarget-lifetime,-Winteger-division,-Wreal-q-constant,-Wunusedand-Wundefined-do-loop. Whole friend group, all invited β¨-Waliasingβ warns you about possible aliasing of dummy arguments. Specifically, it yells if the same actual argument gets associated with a dummy argument that hasINTENT(IN)and a dummy argument withINTENT(OUT)in a call with an explicit interface. Messy behavior honestly.
This example right here triggers the warning:
interface
subroutine bar(a,b)
integer, intent(in) :: a
integer, intent(out) :: b
end subroutine
end interface
integer :: a
call bar(a,a)
-Wampersandβ warns about a missing ampersand in continued character constants. You get this warning with-Wampersand,-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018and-std=f2023. Heads up: when there's no ampersand in a continued character constant, GNU Fortran assumes continuation at the first non-comment, non-whitespace character after the ampersand that started the continuation. iykyk π¦-Warray-temporariesβ warns about array temporaries that the compiler generated. The info from this warning is sometimes genuinely useful for optimization, so you can dodge those temporaries. Iconic for perf girlies π-Wc-binding-typeβ warns if a variable might not be C interoperable. In particular, it warns if the variable was declared using an intrinsic type with default kind instead of using a kind parameter defined for C interoperability in the intrinsicISO_C_Bindingmodule. This option is implied by-Wall.-Wcharacter-truncationβ warns when a character assignment truncates the assigned string. Your string got cut off, no cap βοΈ-Wline-truncationβ warns when a source code line gets truncated. This is implied by-Wall. And for free-form source code, the default is-Werror=line-truncation, so truncations get reported as an actual error. Not a drill πΈ-Wconversionβ warns about implicit conversions that are likely to change the value of the expression after the conversion. Implied by-Wall.-Wconversion-extraβ warns about implicit conversions between different types and kinds. This one does NOT imply-Wconversion. They're separate, bestie, don't assume π«Ά-Wexternal-argument-mismatchβ warns about argument mismatches for dummy external procedures. This is implied by-fc-prototypes-external, because generating a valid C23 interface just isn't possible in that situation. Also implied by-Wall.-Wextraβ turns on some warning options for usages of language features that may be problematic. Currently that includes-Wcompare-reals,-Wunused-parameterand-Wdo-subscript.-Wfrontend-loop-interchangeβ warns when you use-ffrontend-loop-interchangeto do loop interchanges.-Wimplicit-interfaceβ warns if a procedure gets called without an explicit interface. Note though: this only checks that an explicit interface is present. It does not check that the declared interfaces are consistent across program units. So it's a presence check, not a full investigation.-Wimplicit-procedureβ warns if a procedure is called that has neither an explicit interface nor has been declared asEXTERNAL.-Winteger-divisionβ warns if a constant integer division truncates its result. Example:3/5evaluates to0. Yeah. Math said no π-Wintrinsics-stdβ warns if gfortran finds a procedure named like an intrinsic that isn't available in the currently selected standard (the one you set with-std), and because of that treats it as anEXTERNALprocedure. You can use-fall-intrinsicsto never trigger this behavior and always link to the intrinsic regardless of the selected standard. Slay.-Wno-overwrite-recursiveβ do NOT warn when-fno-automaticis used with-frecursive. Recursion breaks if the relevant local variables don't have theAUTOMATICattribute explicitly declared. This option can suppress the warning when you know recursion isn't broken. Super useful for build environments that use-Werror.-Wreal-q-constantβ produces a warning if a real-literal-constant contains aqexponent-letter.-Wsurprisingβ produces a warning when "suspicious" code constructs show up. Technically legal, but usually it means an error has been made. It's giving red flag π©
Currently it produces a warning under these circumstances:
- An
INTEGER-typedSELECT CASEconstruct has aCASEthat can never be matched because its lower value is greater than its upper value. - A
LOGICAL-typedSELECT CASEconstruct has threeCASEstatements. - A
TRANSFERspecifies a source that is shorter than the destination. - The type of a function result is declared more than once with the same type. If
-pedanticor standard-conforming mode is enabled, this is an error. - A
CHARACTERvariable is declared with negative length. - With
-fopenmp, for fixed-form source code, when anomxvendor-extension sentinel is encountered. (The equivalentompx, used in free-form source code, is diagnosed by default.)
-Wtabsβ so by default, tabs are accepted as whitespace, but tabs are not members of the Fortran Character Set. For continuation lines, a tab followed by a digit between 1 and 9 is supported.-Wtabscauses a warning to be issued if a tab is encountered. Note:-Wtabsis active for-pedantic,-std=f95,-std=f2003,-std=f2008,-std=f2018,-std=f2023and-Wall.-Wundefined-do-loopβ warns if aDOloop with step either 1 or -1 yields an underflow or an overflow during iteration of an induction variable of the loop. This option is implied by-Wall.-Wunderflowβ produces a warning when numerical constant expressions that yield an underflow are encountered during compilation. Enabled by default, bestie, it's already on β¨-Wintrinsic-shadowβ warns if a user-defined procedure or module procedure has the same name as an intrinsic. In that case, you might need an explicit interface or anEXTERNALorINTRINSICdeclaration to get calls later resolved to the intrinsic/procedure you actually wanted. This option is implied by-Wall.-Wuse-without-onlyβ warns if aUSEstatement has noONLYqualifier and therefore implicitly imports all public entities of the used module. Just take what you need, babe π-Wunused-dummy-argumentβ warns about unused dummy arguments. This option is implied by-Wall.-Wunused-parameterβ okay so contrary to gcc's meaning of-Wunused-parameter, gfortran's implementation of this option does not warn about unused dummy arguments (that's-Wunused-dummy-argument's whole job), it warns about unusedPARAMETERvalues.-Wunused-parameteris implied by-Wextraif-Wunusedor-Wallis also used.-Walign-commonsβ by default, gfortran warns about any occasion of variables being padded for proper alignment inside aCOMMONblock. You can turn this warning off with-Wno-align-commons. See also-falign-commons.-Wfunction-eliminationβ warns if any calls to impure functions get eliminated by the optimizations enabled by the-ffrontend-optimizeoption. This option is implied by-Wextra.-Wrealloc-lhsβ warns when the compiler might insert code for allocation or reallocation of an allocatable array variable of intrinsic type in intrinsic assignments. In hot loops, that Fortran 2003 reallocation feature may reduce performance π© if the array is already allocated with the correct shape, consider using a whole-array array-spec (e.g.(:,:,:)) for the variable on the left-hand side to prevent the reallocation check. Note that in some cases the warning shows up even if the compiler optimizes the reallocation checks away. For instance, when the right-hand side contains the same variable multiplied by a scalar. See also-frealloc-lhs.-Wrealloc-lhs-allβ warns when the compiler inserts code for allocation or reallocation of an allocatable variable; this includes scalars and derived types. Fancier version of the above π-Wcompare-realsβ warns when comparing real or complex types for equality or inequality. This option is implied by-Wextra.-Wtarget-lifetimeβ warns if the pointer in a pointer assignment might be longer than its target. This option is implied by-Wall.-Wzerotripβ warns if aDOloop is known to execute zero times at compile time. This option is implied by-Wall.-Wdo-subscriptβ warns if an array subscript inside aDOloop could lead to an out-of-bounds access, even if the compiler cannot prove that the statement is actually executed. Like in cases like this:
real a(3)
do i=1,4
if (condition(i)) then
a(i) = 1.2
end if
end do
This option is implied by -Wextra.
-Werrorβ turns all warnings into errors. No mercy mode π
Quick note bestie: some of these have no effect when compiling programs written in Fortran. Yeah, fr fr.
β¨ Options for debugging your program β¨
GNU Fortran has various special options that are used for debugging your program. Debugging era π¦ let's get into it.
-fdebug-aux-varsβ renames the internal variables that the gfortran front end makes and lets a debugger actually see them. After renaming, those internal variable names start with uppercase letters followed by an underscore. It's lowkey essential when you're debugging the compiler's own code generation alongside-fdump-tree-original, and when you want to debug the compiled program itself with-gor-ggdb3. π-ffpe-trap=list β tells the compiler which floating point exception traps to turn on. On most systems, if a floating point exception happens and its trap is enabled, aSIGFPEsignal gets sent, the program aborts, and you get a core file β which is genuinely useful for debugging. π«Ά list is a comma-separated list (it can be empty) made of eithernone(which clears the whole set of exceptions to be trapped) or these exceptions:invalidβ invalid floating point operation, likeSQRT(-1.0)zeroβ division by zerooverflowβ overflow in a floating point operationunderflowβ underflow in a floating point operationinexactβ loss of precision during operationdenormalβ operation performed on a denormal value
The first five match the five IEEE 754 exceptions, and the last one (denormal) is not part of the IEEE 754 standard, but it's available on some common architectures such as x86.
The first three (invalid, zero, and overflow) usually mean something went seriously wrong, so unless your program actually has a plan for handling these exceptions, turning traps on for these three is probably a good idea. β¨
If you use the option more than once on the command line, the lists get joined: ffpe-trap=list1 ffpe-trap=list2 is equivalent to ffpe-trap=list1,list2.
Heads up bestie: once an exception is enabled it cannot be disabled β there's no negative form β the only way out is clearing every trap by specifying none.
Also, like, most floating point operations (many, if not most!) lose precision to rounding, so ffpe-trap=inexact is honestly gonna be uninteresting in practice. π
By default, no exception traps are enabled.
-ffpe-summary=list β picks a list of floating-point exceptions whose flag status gets printed toERROR_UNITwhenSTOPandERROR STOPare invoked. list can benone,all, or a comma-separated list of these exceptions:invalid,zero,overflow,underflow,inexactanddenormal. (Peep-ffpe-trapfor what each exception actually means.) π
If you use the option more than once on the command line, only the last one counts.
By default, a summary for all exceptions but inexact is shown.
-fno-backtraceβ when a serious runtime error hits or a deadly signal goes off (segmentation fault, illegal instruction, bus error, floating-point exception, and the other POSIX signals whose action is core), the Fortran runtime library tries to output a backtrace of the error.-fno-backtracekills the backtrace generation. This option only has influence when you're compiling the Fortran main program. π
π Options for directory search π
These options affect how GNU Fortran searches for files that the INCLUDE directive names, and where it goes looking for previously compiled modules.
It also affects the search paths that cpp uses when cpp preprocesses Fortran source. π¦
-Idir β these affect how theINCLUDEdirective is interpreted (and also the#includedirective of the cpp preprocessor).
Also note: the general behavior of -I and INCLUDE is pretty much the same as -I with #include in the cpp preprocessor, at least when it comes to looking for header.gcc files and other such things.
This path is also used to search for .mod files when previously compiled modules are needed by a USE statement. πΈ
-Jdir β this option says where to put.modfiles for compiled modules. It's also added to the list of directories that aUSEstatement searches.
The default is the current directory.
-fintrinsic-modules-pathdir β this option gives the location of pre-compiled intrinsic modules, in case they're not sitting in the default location the compiler expects. π
π Influencing the linking step π
These options come into play when the compiler links object files into an executable output file. They are meaningless if the compiler isn't doing a link step, periodt.
-static-libgfortranβ on systems that provide libgfortran as both a shared and a static library, this option forces the static version to be used. If no shared version of libgfortran was built when the compiler was configured, this option has no effect.-static-libquadmathβ on systems that provide libquadmath as both a shared and a static library, this option forces the static version to be used. If no shared version of libquadmath was built when the compiler was configured, this option has no effect.
Please note that the libquadmath runtime library is licensed under the GNU Lesser General Public License (LGPL), and linking it statically introduces requirements when redistributing the resulting binaries. β οΈ
π Influencing runtime behavior π
These options affect the runtime behavior of programs compiled with GNU Fortran.
-fconvert=conversion β specifies the representation of data for unformatted files. Valid values for conversion on most systems are:nativeβ the defaultswapβ swap between big- and little-endianbig-endianβ use big-endian representation for unformatted fileslittle-endianβ use little-endian representation for unformatted files
On POWER systems that support -mabi=ieeelongdouble, there are additional options, and you can combine them with the others using commas. Those are:
-fconvert=r16_ieeeβ use IEEE 128-bit format forREAL(KIND=16).-fconvert=r16_ibmβ use IBM long double format forREAL(KIND=16).
This option has an effect only when used in the main program. The CONVERT specifier and the GFORTRAN_CONVERT_UNIT environment variable override the default that -fconvert specifies. π
-frecord-marker=length β specifies the length of record markers for unformatted files. Valid values for length are4and8. The default is4. Careful β this is different from previous versions of gfortran, which specified a default record marker length of8on most systems. If you want to read or write files compatible with earlier versions of gfortran, use-frecord-marker=8.-fmax-subrecord-length=length β specifies the maximum length for a subrecord. The maximum permitted value for length is2147483639, which is also the default. Only really useful for the gfortran testsuite, ngl.-fsign-zeroβ when enabled, floating point numbers of value zero with the sign bit set are written as a negative number in formatted output and treated as negative in theSIGNintrinsic.-fno-sign-zerodoes not print the negative sign of zero values (or values rounded to zero for I/O) and regards zero as a positive number in theSIGNintrinsic, for compatibility with Fortran 77. The default is-fsign-zero. π
π οΈ GNU Fortran Developer Options π οΈ
GNU Fortran has various special options that are used for debugging the GNU Fortran compiler. iykyk π§
-fdump-fortran-globalβ outputs a list of the global identifiers after translating into middle-end representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features that have only recently been added. π-fdump-fortran-optimizedβ outputs the parse tree after front-end optimization. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features that have only recently been added.-fdump-fortran-originalβ outputs the internal parse tree after translating the source program into internal representation. This option is mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features that have only recently been added.-fdump-parse-treeβ outputs the internal parse tree after translating the source program into internal representation. Mostly useful for debugging the GNU Fortran compiler itself. The output generated by this option might change between releases. This option may also generate internal compiler errors for features that have only recently been added. β¨ This option is deprecated; use-fdump-fortran-originalinstead.-save-tempsβ stores the usual "temporary" intermediate files permanently; names them as auxiliary output files, as specified described under GCC-dumpbaseand-dumpdir. π
gfortran -save-temps -c foo.F90
preprocesses input file foo.F90 to foo.fii, compiles to an intermediate foo.s, and then assembles to the (implied) output file foo.o, whereas:
gfortran -save-temps -S foo.F
saves the preprocessor output in foo.fi, and then compiles to the (implied) output file foo.s.
βοΈ Options for code generation conventions βοΈ
These machine-independent options control the interface conventions used in code generation.
Most of them have both positive and negative forms; the negative form of -ffoo would be -fno-foo. In the table below, only one of the forms is listed β the one that is not the default. You can figure out the other form by either removing no- or adding it. π«Ά
-fno-automaticβ treats each program unit (except those marked asRECURSIVE) as if theSAVEstatement were specified for every local variable and array referenced in it. Does not affect common blocks. (Some Fortran compilers provide this option under the name-staticor-save.) The default, which is-fautomatic, uses the stack for local variables smaller than the value given by-fmax-stack-var-size. Use the option-frecursiveto use no static memory.
Local variables or arrays that have an explicit SAVE attribute are silently ignored unless the -pedantic option is added. β οΈ
-ff2cβ generates code designed to be compatible with code generated by g77 and f2c. π
...and here's the tea on how -ff2c actually talks to C, bestie. The calling conventions g77 uses (originally cooked up in f2c) say that functions returning default REAL have to actually hand back the C type double, and functions returning COMPLEX have to smuggle their value out through an extra argument in the calling sequence that points at wherever the return value should live. But under the default GNU calling conventions, those functions just return their stuff like GNU C would β default REAL functions give you the C type float, and COMPLEX functions give you the GNU C type complex. Also, this option drags -fsecond-underscore along with it, unless you explicitly ask for -fno-second-underscore instead.
This does not touch the generation of code that interfaces with the libgfortran library. so don't worry about that part β¨
β οΈ Caution, babe: do not mix Fortran code compiled with-ff2ctogether with code compiled under the default-fno-f2ccalling conventions. CallingCOMPLEXor defaultREALfunctions between program parts compiled with different calling conventions will break at execution time. like genuinely, it will just fall over π
β οΈ Caution round two: this also breaks code that passes intrinsic functions of type defaultREALorCOMPLEXas actual arguments, because the library implementations use the-fno-f2ccalling conventions.
-fno-underscoringβ bestie, this one tells GNU Fortran to stop doing the little name makeover where it appends underscores to the names of entities you declared in your Fortran source. That's it, no secret sauce. π
So with -funderscoring in effect, GNU Fortran tacks one underscore onto external names. Why? Compatibility with code produced by lots of UNIX Fortran compilers, that's why. Note that this does not apply to names declared with C binding, or names inside a module. iykyk.
β οΈ Caution: the default behavior of GNU Fortran is incompatible with f2c and g77. Please use the -ff2c option if you want object files compiled with GNU Fortran to be compatible with object code created with those tools.
Use of -fno-underscoring is not recommended unless you're out here experimenting with things like integrating GNU Fortran into existing system environments (vis-Γ -vis existing libraries, tools, and so on). like it's giving science fair project, not production code π
For example, with -funderscoring, and assuming that j() and max_count() are external functions while my_var and lvar are local variables, a Fortran statement like
I = J() + MAX_COUNT (MY_VAR, LVAR)
is implemented as something akin to the C code:
i = j_() + max_count_(&my_var, &lvar);
With -fno-underscoring, the same statement is implemented as:
i = j() + max_count(&my_var, &lvar);
So using -fno-underscoring lets you directly specify user-defined names while debugging, and while interfacing GNU Fortran code with other languages. which is lowkey iconic.
But β and this is the part nobody wants to hear β just because the names match does not mean the interface GNU Fortran implements for an external name matches the interface some other language implements for that same name. Getting code produced by GNU Fortran to link against code produced by some other compiler using this or any other method is only a small part of the overall solution. Getting both compilers' generated code to agree on issues other than naming can require significant effort, and unlike naming disagreements, linkers normally just cannot detect disagreements in these other areas. π«
Also, note that with -fno-underscoring, the lack of appended underscores introduces the very real possibility that a user-defined external name conflicts with a name in a system library. That could make finding unresolved-reference bugs quite difficult in some cases β they might occur at program run time, and show up only as buggy behavior at run time. nightmare fuel fr fr π
Also also (last note I promise): declaring symbols as bind(C) is a more robust way to interface with code written in other languages or compiled with different Fortran compilers than the command-line options documented in this section. periodt. π
-fsecond-underscoreβ by default, GNU Fortran appends an underscore to external names. If this option is used, GNU Fortran appends two underscores to names that have underscores, and one underscore to names that have no underscores. yes, it's a whole rule and it's unhinged but that's what it does. π
For example, an external name such as MAX_COUNT is implemented as a reference to the link-time external symbol max_count__, instead of max_count_. This is required for compatibility with g77 and f2c, and is implied by use of the -ff2c option.
This option has no effect if -fno-underscoring is in effect. It is implied by the -ff2c option.
-fcoarray=<keyword>β the coarray era is upon us, choose your fighter:noneβ disable coarray support entirely; using coarray declarations and image-control statements produces a compile-time error. (This is the default.)singleβ single-image mode, i.e.num_images()is always one. just one little image chilling.libβ library-based coarray parallelization; a suitable GNU Fortran coarray library such ashttp://opencoarrays.orgneeds to be linked. Alternatively, GCC'slibcaf_singlelibrary can be linked, albeit it only supports a single image.
-fcheck=<keyword>β turns on run-time checks! π The argument shall be a comma-delimited list of the following keywords. Prefixing a check withno-disables it if it was activated by a previous specification. (yes, theno-cancels the earlier one, order matters bestie.)allβ enable all run-time test of-fcheck.array-tempsβ warns at run time when, for passing an actual argument, a temporary array had to be generated. The information generated by this warning is sometimes useful in optimization, in order to avoid such temporaries.
Note: the warning is only printed once per location.
bitsβ enable generation of run-time checks for invalid arguments to the bit manipulation intrinsics.boundsβ enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds, and ensures that all string lengths are equal for character array constructors without an explicit typespec.
Some checks require that -fcheck=bounds is set for the compilation of the main program. don't forget that part or the checks won't do their thing π«Ά
Note: in the future this may also include other forms of checking, e.g., checking substring references.
doβ enable generation of run-time checks for invalid modification of loop iteration variables.memβ enable generation of run-time checks for memory allocation. Note: this option does not affect explicit allocations using theALLOCATEstatement, which are always checked.pointerβ enable generation of run-time checks for pointers and allocatables.recursionβ enable generation of run-time checks for recursively called subroutines and functions that are not marked as recursive. See also-frecursive. Note: this check does not work for OpenMP programs and is disabled if used together with-frecursiveand-fopenmp.
Example: assuming you have a file foo.f90, the command
gfortran -fcheck=all,no-array-temps foo.f90
compiles the file with all checks enabled as specified above except warnings for generated array temporaries. see, the no- did its thing β¨
-fbounds-checkβ deprecated alias for-fcheck=bounds. it's giving legacy, use the new one bestie π-ftail-call-workaround-ftail-call-workaround=nβ okay so some C interfaces to Fortran codes violate the gfortran ABI by omitting the hidden character length arguments as described in. This can lead to crashes because pushing arguments for tail calls can overflow the stack. π
To provide a workaround for existing binary packages, this option disables tail call optimization for gfortran procedures with character arguments. With -ftail-call-workaround=2, tail call optimization is disabled in all gfortran procedures with character arguments; with -ftail-call-workaround=1 or the equivalent -ftail-call-workaround, it's disabled only in gfortran procedures with character arguments that call implicitly prototyped procedures.
Using this option can lead to problems including crashes due to insufficient stack space. π
It is very strongly recommended to fix the code in question. The -fc-prototypes-external option can be used to generate prototypes that conform to gfortran's ABI, for inclusion in the source code. do that instead, queen π
Support for this option will likely be withdrawn in a future release of gfortran.
The negative form, -fno-tail-call-workaround or the equivalent -ftail-call-workaround=0, can be used to disable this option.
Default is currently -ftail-call-workaround; this will change in future releases. so keep an eye on it.
-fcheck-array-temporariesβ deprecated alias for-fcheck=array-temps. another legacy one, sorry babe π-fmax-array-constructor=nβ this option can be used to increase the upper limit permitted in array constructors. The code below requires this option to expand the array at compile time.
program test
implicit none
integer j
integer, parameter :: n = 100000
integer, parameter :: i(n) = (/ (2*j, j = 1, n) /)
print '(10(I0,1X))', i
end program test
β οΈ Caution: this option can lead to long compile times and excessively large object files. it will absolutely eat your afternoon, no cap.
The default value for n is 65535.
-fmax-stack-var-size=nβ this option specifies the size in bytes of the largest array that is put on the stack; if the size is exceeded, static memory is used (except in procedures marked asRECURSIVE). Use the option-frecursiveto allow for recursive procedures that do not have aRECURSIVEattribute, or for parallel programs. Use-fno-automaticto never use the stack. pick your lane bestie.
This option currently only affects local arrays declared with constant bounds, and may not apply to all character variables. Future versions of GNU Fortran may improve this behavior. (translation: it's a work in progress, don't come for me πΈ)
The default value for n is 65536.
-fstack-arraysβ adding this option makes the Fortran compiler put all arrays of unknown size and array temporaries onto stack memory. If your program uses very large local arrays, it's possible that you have to extend your runtime limits for stack memory on some operating systems. heads up, that's a you problem but it's a fixable one π«Ά
This flag is enabled by default at optimization level -Ofast unless -fmax-stack-var-size is specified.
okay bestie we're back in the OPTIONS section and there is SO much more tea to spill π Here we go, one flag at a time, no skips, no cap.
-fpack-derivedβ this tells GNU Fortran to squish derived type members together as tight as physically possible π«. Warning though, and it's giving red flag: code compiled with this flag is likely to be incompatible with code compiled without it π and might also run slower. Iconic for size, not for speed.-frepack-arraysβ sometimes GNU Fortran passes assumed shape array sections through a descriptor that's describing a noncontiguous lil chunk of memory (messy π΅βπ«). This option adds code to the function prologue that repacks that data into one contiguous block at runtime β¨. Result? Faster accesses to the array ποΈ. BUT it can bring significant overhead to the function call, especially when the data you passed in is noncontiguous. Trade-offs, always trade-offs.-fshort-enumsβ exists purely for interoperability with C code that was compiled with the-fshort-enumsoption π€. It makes GNU Fortran pick the smallestINTEGERkind that the given enumerator set fits into, and then it gives all of its enumerators that kind. Matchy matchy, slay.-finline-arg-packingβ when you pass an assumed-shape argument of a procedure as an actual argument to an assumed-size or explicit size thing, or as an argument to a procedure with no explicit interface, the argument may have to be packed β aka put into contiguous memory π¦. Example time, the call tofooin:
subroutine foo(a)
real, dimension(*) :: a
end subroutine foo
subroutine bar(b)
real, dimension(:) :: b
call foo(b)
end subroutine bar
When -finline-arg-packing is in effect, that packing is done by inline code π§΅β¨. More optimization opportunities, but bigger code size. Also lowkey important: -finline-arg-packing is implied by any of the -O options except when you're optimizing for size via -Os. And heads up π£οΈ β if your code has a very large number of arguments that need packing, code size and compilation time can get excessive π³. If that's your situation, it may be better to just disable this option. You can find instances of packing by using -Warray-temporaries π.
-fexternal-blasβ makesgfortrangenerate calls to BLAS functions for some matrix operations likeMATMULinstead of using our own algorithms β but only if the size of the matrices involved is bigger than a given limit (peep-fblas-matmul-limitπ). This may be profitable if you've got an optimized vendor BLAS library lying around. The BLAS library has to be specified at link time. Don't forget that part π .-fblas-matmul-limit=nβ only significant when-fexternal-blasis in effect, no exceptions. Matrix multiplication of matrices with size larger than (or equal to) n gets performed by calls to BLAS functions, while everything else is handled by gfortran internal algorithms π. If the matrices involved are not square, the size comparison uses the geometric mean of the dimensions of the argument and result matrices (math girlie behaviour, we love it π).
The default value for n is 30. Periodt.
-finline-intrinsics-finline-intrinsics=intr1,intr2,...β prefer generating inline code over calls to libgfortran functions to implement intrinsics β¨. So here's the lore: usage of intrinsics can be implemented either by generating a call to the libgfortran library function, or by directly generating inline code. For most intrinsics only a single variant is available and there's genuinely no choice of implementation π€·ββοΈ. But some intrinsics can use a library function or inline code, and inline code typically offers opportunities for additional optimization over a library function π₯. With-finline-intrinsics=...or-fno-inline-intrinsics=..., the choice applies only to the intrinsics present in the comma-separated list you hand over as the argument.
For each intrinsic, if no choice of implementation was made through either of the flag variants, a default behavior is chosen depending on optimization: library calls get generated when not optimizing or when optimizing for size; otherwise inline code is preferred π.
The set of intrinsics allowed as argument to -finline-intrinsics= is currently limited to MAXLOC and MINLOC π. The effect of the flag is moreover limited to calls of those intrinsics without DIM argument and with ARRAY of a non-CHARACTER type. The case of rank-1 argument and DIM argument present β i.e. MAXLOC(A(:),DIM=1) or MINLOC(A(:),DIM=1) β is inlined unconditionally for numeric rank-1 array argument A β‘.
-finline-matmul-limit=nβ when front-end optimization is active, some calls to theMATMULintrinsic function get inlined π§¬. This may result in code size increase if the size of the matrix can't be determined at compile time, because code for both cases is generated (double the code, double the chaos π). Setting-finline-matmul-limit=0disables inlining in all cases. Setting this option with a value of n produces inline code for matrices with size up to n. If the matrices involved are not square, the size comparison is performed using the geometric mean of the dimensions of the argument and result matrices π.
The default value for n is 30. And surprise, the -fblas-matmul-limit can be used to change this value π―ββοΈ.
-frecursiveβ allows indirect recursion by forcing all local arrays to be allocated on the stack π. Careful bestie: this flag cannot be used together with-fmax-stack-var-size=or-fno-automaticπ«. Pick a lane.-finit-local-zero,-finit-derived,-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>,-finit-logical=<true|false>,-finit-character=nβ the whole init family, here's the rundown π«. The-finit-local-zerooption instructs the compiler to initialize localINTEGER,REAL, andCOMPLEXvariables to zero,LOGICALvariables to false, andCHARACTERvariables to a string of null bytes. Then there are finer-grained initialization options:-finit-integer=n,-finit-real=<zero|inf|-inf|nan|snan>(which also initializes the real and imaginary parts of localCOMPLEXvariables),-finit-logical=<true|false>, and-finit-character=n(where n is an ASCII character value).
With -finit-derived, components of derived type variables are initialized according to these flags π§©. Components whose type is not covered by an explicit -finit-* flag are treated as described above with -finit-local-zero.
These options do not initialize:
- objects with the
POINTERattribute - allocatable arrays
- variables that appear in an
EQUIVALENCEstatement.
(These limitations may be removed in future releases π β so it's giving "watch this space".)
Note that the-finit-real=nanoption initializesREALandCOMPLEXvariables with a quiet NaN πΆ. For a signalling NaN use-finit-real=snanβ however, note that compile-time optimizations may convert them into quiet NaN, and that trapping needs to be enabled (e.g. via-ffpe-trap). Not me warning you twice, but I'm warning you twice π.
The -finit-integer option parses the value into an integer of type INTEGER(kind=C_LONG) on the host. Said value is then assigned to the integer variables in the Fortran code, which might result in wraparound if the value is too large for the kind π.
Finally, note that enabling any of the -finit-* options silences warnings that would have been emitted by -Wuninitialized for the affected local variables π€«. You traded warnings for defaults, bestie.
-falign-commonsβ by default,gfortranenforces proper alignment of all variables in aCOMMONblock by padding them as needed π§±. On certain platforms this is mandatory, on others it increases performance. But if aCOMMONblock is not declared with consistent data types everywhere, this padding can cause trouble π¬, and-fno-align-commonscan be used to disable automatic alignment. The same form of this option should be used for all files that share aCOMMONblock β consistency is the vibe. And to avoid potential alignment issues inCOMMONblocks, it's recommended to order objects from largest to smallest π.-fno-protect-parensβ by default the parentheses in an expression are honored for all optimization levels, such that the compiler does no reassociation π‘οΈ. Using-fno-protect-parensallows the compiler to reorderREALandCOMPLEXexpressions to produce faster code πββοΈ. Note that for the reassociation optimization,-fno-signed-zerosand-fno-trapping-mathneed to be in effect. The parentheses protection is enabled by default, unless-Ofastis given β that's the one case it dips out on you π .-frealloc-lhsβ an allocatable left-hand side of an intrinsic assignment is automatically (re)allocated if it's either unallocated or has a different shape π. The option is enabled by default except when-std=f95is given. See also-Wrealloc-lhs. π―-faggressive-function-eliminationβ functions with identical argument lists are eliminated within statements, regardless of whether those functions are markedPUREor not π―ββοΈπ―ββοΈ. For example, in:
a = f(b,c) + f(b,c)
there is only a single call to f π. Efficiency. But it only works if -ffrontend-optimize is in effect β no freeloading.
-ffrontend-optimizeβ this option performs front-end optimization, based on manipulating parts of the Fortran parse tree π³. Enabled by default by any-Ooption except-O0and-Og. Optimizations enabled by this option include:- inlining calls to
MATMUL, - elimination of identical function calls within expressions,
- removing unnecessary calls to
TRIMin comparisons and assignments, - replacing
TRIM(a)witha(1:LEN_TRIM(a))and - short-circuiting of logical operators (
.AND.and.OR.).
- inlining calls to
It can be deselected by specifying -fno-frontend-optimize πͺ.
-ffrontend-loop-interchangeβ attempt to interchange loops in the Fortran front end where profitable π. Enabled by default by any-Ooption. At the moment, this option only affectsFORALLandDO CONCURRENTstatements with several forall triplets. Niche but cute.
π ENVIRONMENT π
The gfortran compiler currently does not make use of any environment variables to control its operation above and beyond those that affect the operation of gcc π
ββοΈ. That's it, that's the section. No secret env vars, bestie, it's giving minimalism.
π BUGS π
For instructions on reporting bugs, see <file:///usr/share/doc/gcc-15/README.Bugs>. Go tell them everything, they wanna hear it π«Ά.
π SEE ALSO π
gpl(7), gfdl(7), fsf-funding(7), cpp(1), gcov(1), gcc(1), as(1), ld(1), gdb(1), dbx(1) and the Info entries for gcc, cpp, gfortran, as, ld, binutils and gdb.
a whole friend group of manual pages, we love a crossover episode π
β¨ AUTHOR β¨
See the Info entry for gfortran for contributors to GCC and GNU Fortran π.
π COPYRIGHT (yes bestie, the legal bit, stay with me) π
Copyright (c) 2004-2025 Free Software Foundation, Inc. π«Ά
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with the Invariant Sections being "Funding Free Software", the Front-Cover Texts being (a) (see below), and with the Back-Cover Texts being (b) (see below). A copy of the license is included in the gfdl(7) man page. πβ¨
Translation for the girlies: you can copy, share and remix this doc, bestie, but there are rules, and the two unskippable (invariant) bits are listed right there. It's giving "share freely but read the terms." π
π (a) The FSF's Front-Cover Text is:
A GNU Manual
π (b) The FSF's Back-Cover Text is:
You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.
And that's the whole page, bestie, you made it to the end, no cap. π¦ This icon of a man page is gcc-15, dated 2026-09-15, and it's filed under GFORTRAN(1) β go forth and compile, main character. ππβ¨
π¦ where this page comes from
- ubuntu stonking: gfortran-15-powerpc-linux-gnu 15.3.0-4ubuntu1cross1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms