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.

7
  • Please use tag fortran for all Fortran questions. I note others have asked before stackoverflow.com/questions/49344474/… Also notice this issue stackoverflow.com/questions/50321283/… Commented Jun 11, 2018 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. Commented Jun 11, 2018 at 15:36
  • So you are not executing the gfortran from Homebrew but the old version from Anaconda. Commented Jun 11, 2018 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. Commented Jun 11, 2018 at 22:52
  • Are you using an editor or IDE to launch your code for build and run? If so which one? Commented Jun 12, 2018 at 1:40

1 Answer 1

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 
Sign up to request clarification or add additional context in comments.

8 Comments

I don't understand how your answer can be a solution to my question.
@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.
I understand now. I use a Mac. I put module use --append "$HOME/.modules" at the end of .bash_profileand delete any reference to Anaconda. Then I created this file named conda in the .modulesfolder: ``` $ cat .modules/conda #%Module1.0 module-whatis "add ~/anaconda3 to path" prepend-path PATH /Users/sergiobacelar/anaconda3/bin```. But when I do module load condaI get -bash: module: command not found.
@sbac I've updated the answer with install instructions
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 <root@localhost>
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.