1

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.

sbac
  • 1,897
  • 1
  • 18
  • 31
  • Please use tag [tag:fortran] for all Fortran questions. I note others have asked before https://stackoverflow.com/questions/49344474/dyld-library-not-loaded-rpath-libgfortran-3-dylib Also notice this issue https://stackoverflow.com/questions/50321283/conda-gfortran-on-osx-failed-link-issue – Vladimir F Героям слава Jun 11 '18 at 15:35
  • If you want your question answered so that it does not remain unanswered like the first one I linked, we will need more information. Especially whether there is `libgfortran.3.dylib` anywhere on your computer and which exact version of gfortran you have. – Vladimir F Героям слава Jun 11 '18 at 15:36
  • So you are not executing the gfortran from Homebrew but the old version from Anaconda. – Vladimir F Героям слава Jun 11 '18 at 16:13
  • I have a problem to access `gfortran` from Homebrew because I have to give precedence to Anaconda in my `$PATH` because I want to use Anaconda Python environment. – sbac Jun 11 '18 at 22:52
  • Are you using an editor or IDE to launch your code for build and run? If so which one? – Natsfan Jun 12 '18 at 01:40
  • @jmh Yes. Geany. – sbac Jun 12 '18 at 07:01
  • Solved! I edited `.bash_profile` to give precedence to `/usr/local/bin`. I deleted any path to Anaconda in `.bash_profile`and uninstalled and the reinstalled `gcc` using `Homebrew`. – sbac Jun 12 '18 at 11:04

1 Answers1

2

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
ptb
  • 2,138
  • 1
  • 11
  • 16
  • I don't understand how your answer can be a solution to my question. – sbac Jun 11 '18 at 22:53
  • @sbac your problem is that you have two conflicting installations of a library. The only way to solve that problem is to adjust your PATH (and potentially other environment variables) so that the appropriate installation is chosen when needed. This is precisely what modules are for. In terminals where you will be using anaconda, run `module load conda`. In terminals where you will be using the homebrew gfortran, don't load the module. – ptb Jun 12 '18 at 03:06
  • I understand now. I use a Mac. I put `module use --append "$HOME/.modules"` at the end of `.bash_profile`and delete any reference to Anaconda. Then I created this file named `conda` in the `.modules`folder: ``` $ cat .modules/conda #%Module1.0 module-whatis "add ~/anaconda3 to path" prepend-path PATH /Users/sergiobacelar/anaconda3/bin```. But when I do `module load conda`I get `-bash: module: command not found`. – sbac Jun 12 '18 at 09:43
  • @sbac I've updated the answer with install instructions – ptb Jun 12 '18 at 12:43
  • I added ` . /usr/local/opt/modules/init/bash ` before `module use...` and after doing `module load conda` I got `Module ERROR: Magic cookie '#%Module' missing In '/Users/sergiobacelar/.modules/conda' Please contact ` – sbac Jun 12 '18 at 14:39
  • @sbac what is the first line of your `.modules/conda` file? – ptb Jun 12 '18 at 15:00
  • $ cat .modules/conda – sbac Jun 12 '18 at 15:02
  • @sbac we have a slight misunderstanding. the `$ cat .modules/conda` was meant to represent the use of the `cat` unix utility on the file `.modules/conda`. This utility (the way I used it) simply prints the contents of the file to stdout. If you delete that line and make sure the first line is `#%Module1.0` then everything should work. – ptb Jun 12 '18 at 15:07