sbac
sbac

Reputation: 2081

Error running Fortran on Mac

I am running macOS 10.13.5 and I have installed Fortran using Homebrew. I can compile and build a program like this:

program HelloWorld
    write(*,*)'Hello World'
end program

But when I try to run it I get the same error:

dyld: Library not loaded: @rpath/libgfortran.3.dylib
  Referenced from: /Users/sergiobacelar/Documents/books2calibre/books_software/feher_fortran/prog01/prog01_01/Build/prog
  Reason: image not found
/var/folders/tq/f5jbfqp97y52w_y7byn05_fw0000gn/T/geany_run_script_2Q4DKZ.sh: line 7: 47712 Abort trap: 6           "Build/prog"

I have libgfortran.3.dylib inside anaconda3/lib and I have gcc 8.1.0 in homebrew but when I do gfortran -v I get gcc 4.8.5 from Anaconda.

Upvotes: 1

Views: 1196

Answers (1)

ptb
ptb

Reputation: 2148

I use anaconda/miniconda quite a bit on Linux and mac environments. Modules (https://en.wikipedia.org/wiki/Environment_Modules_(software)) are a great way to keep it from polluting your environment. As an example, at the end of my .bashrc file, I have:

module use --append "$HOME/.modules"

This directory contains a module file for conda:

$ cat .modules/conda
#%Module1.0

module-whatis  "add ~/miniconda3 to path"

prepend-path   PATH /Users/ptb/miniconda3/bin

A $ module load conda will then adjust the PATH, making all miniconda related things visible.

Edit:

I wrote the first part of this answer on my linux machine where modules are installed by default and forgot that 2 things are needed to make it work on a mac. On a mac, modules can be installed via homebrew with brew install modules. One then needs to put the following before module use ...:

.  /usr/local/Modules/default/init/bash

Upvotes: 2

Related Questions