William.Hatheway
Active member
The recent releases of Ubuntu 22, Ubuntu 23, Ubuntu 24, and newer by Canonical have introduced several significant changes to their base operating system, including notable updates to the GNU Compiler Collection (GCC). Specifically, these versions have been upgraded to GCC 11 and GCC 12, respectively. These updates bring a range of improvements and new features to the compilers, enhancing performance, security, and compatibility with modern software practices.
However, these advancements come with certain challenges, particularly concerning the compatibility of legacy Fortran code. GCC versions greater than 9 have deprecated certain antiquated Fortran commands, which has led to compatibility issues during the installation and compilation of software such as the Weather Research and Forecasting (WRF) model. This is due to the default disabling of older code syntaxes in these newer GCC versions, resulting in compilation errors.
The required environment variables and their values are as follows:
These commands configure the compiler to:
However, these advancements come with certain challenges, particularly concerning the compatibility of legacy Fortran code. GCC versions greater than 9 have deprecated certain antiquated Fortran commands, which has led to compatibility issues during the installation and compilation of software such as the Weather Research and Forecasting (WRF) model. This is due to the default disabling of older code syntaxes in these newer GCC versions, resulting in compilation errors.
Compatibility Issues with Legacy Fortran Code
Legacy Fortran code often contains syntax and coding practices that have been superseded or deprecated in more recent versions of the Fortran standard. When compiling such code with modern compilers like GCC 11 or GCC 12, developers may encounter errors related to argument mismatches and invalid Binary, Octal, and Hexadecimal (BOZ) literal constants. These errors can prevent the successful compilation of the WRF model and other related applications.Addressing Compatibility with Environment Variables
To ensure compatibility with legacy Fortran code while compiling libraries for WRF, WPS (WRF Preprocessing System), and other related software, it is necessary to set specific environment variables before the compilation process. These variables instruct the compiler to allow certain older code syntaxes, thus preventing the common errors associated with deprecated features.The required environment variables and their values are as follows:
Bash:
export fallow_argument=-fallow-argument-mismatch
export boz_argument=-fallow-invalid-boz
export FFLAGS="$fallow_argument $boz_argument -m64"
export FCFLAGS="$fallow_argument $boz_argument -m64"
These commands configure the compiler to:
- Allow Argument Mismatches: The -fallow-argument-mismatch flag enables the compiler to accept argument mismatches, which are a frequent occurrence in older Fortran codes.
- Allow Invalid BOZ Literals: The -fallow-invalid-boz flag permits the use of invalid BOZ literal constants, another common feature in legacy Fortran code.
Consideration of the -std=legacy Flag
Another potential solution for enabling legacy Fortran code compatibility is the use of the -std=legacy flag in GCC. This flag instructs the compiler to accept all legacy Fortran code, effectively bypassing many of the issues caused by deprecated syntax and features. However, its usage might lead to additional complications. The -std=legacy flag can allow outdated coding practices that may not be compatible with modern Fortran standards, potentially leading to unforeseen issues in the software's execution and performance.Recommendations for Developers and Researchers
- Set the Environment Variables: Use the specific environment variables (-fallow-argument-mismatch and -fallow-invalid-boz) to enable the older Fortran code syntaxes without broadly enabling all legacy features.
- Test Extensively: Ensure thorough testing of the compiled software to identify and address any issues that might arise from the combination of legacy code and modern compiler practices.
- Refer to GCC Documentation: Consult the detailed documentation and explanations of these compiler options in the GCC online documentation, particularly in the section dedicated to Fortran Dialect Options: Fortran Dialect Options (The GNU Fortran Compiler).