1

I have tried to compile a simple helloworld.f95 on my Mac, using emacs. The root of emacs was set in the directory containing helloworld.f95. I used the following commands

M-x compile
gfortran -o helloworld helloworld.f95

I got the following error:

-*- mode: compilation; default-directory: "~/Desktop/fortran/" -*-
Compilation started at Wed Sep  4 17:37:51

gfortran -o helloworld helloworld.f95
/bin/bash: gfortran: command not found

Compilation exited abnormally with code 127 at Wed Sep  4 17:37:51

I have previously been able to compile with the same command on the terminal. Fortran was installed on my mac by following the instructions on this link: http://www.lapk.org/gfortran/gfortran.php?OS=7

The location in which gfortran is installed is at:

Desktop$ which gfortran
/usr/local/bin/gfortran

How do I compile .f95 files from emacs, as well as run them?

Tian
  • 288
  • 1
  • 8

1 Answers1

1

As mentioned by @JeanPierre , the problem was because the location of gfortran was not added to the PATH environment variable for the emacs shell. Thus the shell did not know where to look to find the command. To do so (and to make the PATH environment readily available for editing) I added this code block into my initialisation file: ~/.emacs.d/init.el

;; defining "PATH"
(setenv "PATH" (mapconcat identity
                          '("/usr/local/bin"
                            "/usr/bin"
                            "/bin")
                          ":"))
Tian
  • 288
  • 1
  • 8