50

I'm using the OS X devel version of R

R Under development (unstable) (2014-05-27 r65787)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

with GNU Fortran (GCC) 4.2.3 (from Simon's site) and version 5.1.1 of Xcode's command line tools.

When building from source, I get errors like:

gfortran-4.8   -fPIC  -g -O2  -c altmov.f -o altmov.o
make: gfortran-4.8: No such file or directory

I'm not sure what to do here. I could create an alias to the version I have but I'm not sure if it really needs 4.8 or not.

Thanks,

Max

topepo
  • 13,534
  • 3
  • 39
  • 52
  • 1
    Do you really need R devel version? – Fernando May 28 '14 at 16:01
  • 3
    Yes. CRAN maintainers almost always ask you to build and check using a very recent devel version. – topepo May 28 '14 at 17:20
  • You can use the winbuilder service. See http://cran.r-project.org/web/packages/policies.html. I use it and it works. – Bhas May 28 '14 at 17:34
  • 5
    See http://r.research.att.com/libs/ and look for gfortran-4.8.2. To install follow the instructions at the end of the page. And look at this R-SIG-Mac mailinglist thread: https://stat.ethz.ch/pipermail/r-sig-mac/2014-May/010894.html. If you have an Intel Core 2 Duo this version of gfortran won't wotk. – Bhas May 28 '14 at 17:37
  • Bhas thanks for the response. I unpacked and it starts fine (testing with `gfortran-4.8 --version`) but now get the error `f951: internal compiler error: Abort trap: 6`. – topepo May 28 '14 at 17:49
  • Following the R-SIG-MAC link I installed the Snow leopard version and it works fine (although I have quad-core Xeon) – topepo May 28 '14 at 17:59
  • You are probably doing something with real or double precision numbers. That was what I mentioned in my post to the R-SIG-Mac mailinglist. You should now also respond to that thread. It should work on a quad-core Xeon as far as I can tell. – Bhas May 28 '14 at 18:49
  • According to this page http://cran.r-project.org/web/checks/check_flavors.html the Mavericks version of R is built with gfortran 4.8.2 on a quad-core Xeon. So something is not quite right. Do post to the thread mentioned. – Bhas May 28 '14 at 18:57
  • I confirm I also encountered a missing gfortran-4.8 on OS 10.9. @Bhas please post your comment as an answer! – smci Jul 25 '14 at 06:28

12 Answers12

53

Type these two lines in your terminal, direct quote:

curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxj gfortran-4.8.2-darwin13.tar.bz2 -C /

It will download you the gfortran for Mavericks (which is missing in your system at the moment) and will install it in your system. At least, this solved the same problem for me

(I'm running late 2011 MacPro, Mavericks).

Claus Wilke
  • 16,992
  • 7
  • 53
  • 104
TheBigMike
  • 547
  • 4
  • 3
  • I still get missing gfortran-4.8 when installing igraph after this. It seems although ``/usr/local/bin`` is in PATH in R session, the compilation process ignores this and cannot find gfortran-4.8. – xgdgsc Oct 20 '14 at 09:29
  • 2
    This worked perfect for me too. This is not an Rstudio problem, since I encountered the error installing package source from the console. Cheers – Marc in the box Jan 21 '15 at 17:34
  • great answer. google+stackoverflow = problem solved in 30 seconds – zach Jan 29 '15 at 21:16
  • 3
    Solves the problem for me (Yosemite) – Andy Barbour Feb 05 '15 at 01:52
  • Currently I have **gfortran-5** installed on my Mac (installed via homebrew, I believe)--will using your code to download **gfortran-4.8** cause any problems down the road? – Steve S Aug 22 '15 at 21:37
  • 3
    Yes, this will cause problems with Homebrew; this is an inelegant way to install gfortran and will cause conflicts with Homebrew's gcc formula. – Tim Smith Aug 27 '15 at 03:23
  • Does anyone also have problems with sudo installing binaries from an unknown source?? – normanius Mar 23 '22 at 22:43
  • I found this URL more trustworthy: https://mac.r-project.org/libs/gfortran-4.8.2-darwin13.tar.bz2 – normanius Mar 23 '22 at 22:44
20

Edit: I now think this is best accomplished using Homebrew:

brew reinstall gcc48 --with-fortran

While I think the following procedure will work, it is not as clean. However, I still recommend configuring ~/.R/Makevars as described below.

To build on the answer by @TheBigMike, I used the following procedure to install gfortran-4.8 alongside homebrew, and then configured R to select this fortran compiler.

First, download and unpack gfortran 4.8:

su admin
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
mkdir /tmp/gfortran
tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /tmp/gfortran

Delete the gfortran file alias that interferes with homebrew:

rm /tmp/gfortran/usr/local/bin/gfortran

Install gfortran 4.8

cp -r /tmp/gfortran/usr/local/ /usr/local

To tell R to use gfortran 4.8, create a file called ~/.R/Makevars:

mkdir -p ~/.R
touch ~/.R/Makevars

Put the following into ~/.R/Makevars:

FLIBS=""
F77="gfortran-4.8"
FC="gfortran-4.8"

Now restart R. Once R has been restarted, any packages that depend upon fortran 4.8 should now work. homebrew should be undisturbed.

lune
  • 48
  • 1
  • 4
  • Thanks for the excellent answer. I tired `brew reinstall gcc48 --with-fortran`, but still get an error: `ld: library not found for -lgfortran`. However, when I follow your procedure below, it works! brew then complains: `Warning: Unbrewed dylibs were found in /usr/local/lib.` Should I worry about that? – Zach Dec 30 '16 at 17:41
  • Ahah! If I add `FLIBS = ""` to my `~/.R/Makevars`, the `brew reinstall gcc48 --with-fortran` method works. – Zach Dec 30 '16 at 17:46
  • 2
    I got a "tar: Error opening archive: Unrecognized archive format" after the `tar` command, but I was able to solve it by using `-L` flag in curl: `curl -0L` – User800701 Feb 07 '20 at 21:29
12

I encountered the same problem, albeit on R Studio. The following worked for me, although, I had to reinstall all my R packages after (note: the re-installations took awhile and look like quite a bit was going on, unsure if these were the appropriate steps, use at own risk):

Download latest R Studio version and then following in terminal: brew install gcc brew update && brew reinstall r brew link --overwrite r

grantog
  • 168
  • 1
  • 10
4

This is explained nicely in Rcpp FAQ, section 2.16. Basically you need to install gfortran (homebrew install gcc or the other way) and then modify Makeconf to point FLIBS to the relevant fortran libraries.

These were the steps which worked for me:

  1. Install gcc48 via homebrew

  2. Make sure that gfortran and gfortran-4.8 point to the newly installed versions.

  3. Comment the FLIBS variable in /Library/Frameworks/R.framework/Resources/etc/Makeconf.

The step 3 was the most important one, because it is designed to work with the gfortran which is installed in the way @TheBigMike suggested, i.e. by downloading and extracting the archive gfortran-4.8.2-darwin13.tar.bz2.

mpiktas
  • 11,258
  • 7
  • 44
  • 57
3

The following worked for me on OSX High Sierra and RStudio 1.1.423:

  1. Install gcc/gfortran via Homebrew: brew install gcc
  2. Edit /Library/Frameworks/R.framework/Resources/etc/Makeconf and replace all instances of gfortran-4.8 with gfortran
  3. Also replace FLIBS = -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 with FLIBS = -L/usr/local/lib/gcc/7/ -lgfortran -lquadmath -lm.
  4. Reattempt installing the package.
  • This worked to get rid of the fortran error for me, but is causing compilation to fail for other (diverse) reasons for everything I have tried. MacOS High Sierra, R version 3.3.3 – Peter M Mar 15 '18 at 02:39
  • It worked for me. Gcc via Homebrew was already installed on my laptop (so I skipped step 1), what was missing was the proper configuration in the Makeconf file. – domi Sep 04 '18 at 12:58
2
  1. Install gcc/gfortran via Homebrew: brew install gcc
  2. Make sure you replace it is not done automatically: /Library/Frameworks/R.framework/Resources/etc/Makeconf and replace all instances of gfortran-4.8(or any number) with gfortran
  3. Replace FLIBS = -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm to FLIBS = -L/usr/local/lib/gcc/7/ -lgfortran -lquadmath -lm
  4. Reinstall the package for me was robustbase that was required by fpc library
dguardia
  • 21
  • 1
  • worked for me. Note: change the 7 in gcc/7 to whatever version of gcc you have (e.g., it's 2022 now and I used gcc/12). – Cliff Bueno Dec 05 '22 at 20:15
1

Got the same issue and found a statement in the R cran site (https://cran.ism.ac.jp/) In the latest OSX such as High Sierra, some necessary libs are not included and these have to be installed. The page kindly explains this, quoting

Important: this release uses Clang 6.0.0 and GNU Fortran 6.1, neither of which is supplied by Apple. If you wish to compile R packages from sources, you will need to download and install those tools - see the tools directory.

I resolved the issues (missing gfortran etc.) with applying the following two packages, here.

  1. clang-6.0.0.pkg (OS X 10.11+, signed, 64-bit) MD5-hash: c29700c4e7b2914073ef7e741eb105bc (ca. 418Mb)
  2. gfortran-6.1.pkg (OS X 10.11+, signed, 64-bit) MD5-hash: 201026216e8b373d9cd2efc0cc474bb8 (ca. 73Mb)
Tsuney
  • 11
  • 1
1

This answer by thebigmike suggests:

Type these two lines in your terminal, direct quote:

curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxj gfortran-4.8.2-darwin13.tar.bz2 -C /

but

curl -OL http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2

Solves the problem for me!

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • 1
    [That answer](https://stackoverflow.com/a/25912049/4826457) was by [TheBigMike](https://stackoverflow.com/users/4054331/thebigmike) Claus is an editor of that answer. – Suraj Rao Jan 27 '21 at 05:31
0

Updated version of RStudio (Version 0.98.1091) seems to fix this.

  • This should be posted as a comment rather as an answer. Or please at list provide a source (release note which tells something about the bug, etc) – AFract Dec 08 '14 at 14:44
  • I got this error with 0.99, so this does not seem to be fixed (unless they reverted the fix). – burger Mar 14 '16 at 20:52
0

Make sure R is updated to version >= 4.0 (for previous versions this might help: https://cran.ism.ac.jp/bin/macosx/tools/)

Download and install the GNU fortran compiler found here: https://mac.r-project.org/tools/

Make sure you add /usr/local/gfortran/bin to your PATH in order to use this compiler. This can be done, e.g. by

export PATH=$PATH:/usr/local/gfortran/bin
0

If you are having trouble installing software that depends on FORTRAN on Max OS 10.15 or later. The best solution is to update R to at least version 4.0.0

-1

Installing gcc via homebrew give me gfortran:

brew install gcc

Then:

$which gfortran
/usr/local/bin/gfortran
Zach
  • 29,791
  • 35
  • 142
  • 201