Mod:Hunt Research Group/Gfortran

From wiki
Jump to navigation Jump to search

GFortran

quick start

sudo port install gcc12
sudo port select --set gcc mp-gcc12
gfortran -v

first install a gcc compiler using macports

  • type
sudo port search --name gcc*
  • select one to install for example
sudo port install gcc12
  • check what installs are active
sudo port installed 'gcc*'
  • the files will be installed in /opt/local/bin
  • a check will not show the new compiler
gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
  • check gfortran version does not work
gfortran -v
port installed '*fortran*' returns None of the specified ports are installed.
  • because the MacPorts are installed in /opt and not /usr, you either need to either specify the full path, or explicitly set which compiler to use on your system.
  • you can use MacPorts to select the default compiler
port select --list gcc
Available versions for gcc:
	mp-gcc11
	mp-gcc12
	none
sudo port select --set gcc mp-gcc12
Selecting 'mp-gcc12' for 'gcc' succeeded. 'mp-gcc12' is now active.
check the gcc again
port select --list gcc
Available versions for gcc:
	mp-gcc11
	mp-gcc12 (active)
	none
gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin21/12.3.0/lto-wrapper
Target: x86_64-apple-darwin21
Configured with: /opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_lang_gcc12/gcc12/work/gcc-12.3.0/configure --prefix=/opt/local --build=x86_64-apple-darwin21 --enable-languages=c,c++,objc,obj-c++,lto,fortran,jit --libdir=/opt/local/lib/gcc12 --includedir=/opt/local/include/gcc12 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-12 --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-12 --with-gxx-include-dir=/opt/local/include/gcc12/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local --with-zstd=/opt/local --enable-checking=release --disable-multilib --enable-lto --enable-libstdcxx-time --with-build-config=bootstrap-debug --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --enable-host-shared --with-darwin-extra-rpath=/opt/local/lib/libgcc --with-libiconv-prefix=/opt/local --disable-tls --with-gxx-libcxx-include-dir=/opt/local/libexec/gcc12/libc++/include/c++/v1 --with-pkgversion='MacPorts gcc12 12.3.0_0+stdlib_flag' --with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.3.0 (MacPorts gcc12 12.3.0_0+stdlib_flag) 

using fortran

  • normally you will just need to "make" a package downloaded
  • alternatively to compile individual files
  • To compile file source.f90
gfortran -c source.f90
  • To link into runfile executable
gfortran -o executable object1.o object2.o ...
  • To combine the above
gfortran -o executable source1.f90 source2.f90
  • .f files are assumed fixed form files
  • .f90 or .f95 are assumed free form files
  • note: on old macs the default version of fortran is /usr/local/gfortran and /usr/local/bin/gfortran
if required use sudo rm -r /usr/local/gfortran /usr/local/bin/gfortran