gfortran issue (trying to address compilation failed for package)

RandomFields is a dependency needed for the NLMR package. Neither of these are on cran anymore so I am trying to download older versions by downloading RandomFields first and then my plan is to download NLMR.

I've downloaded older versions of packages before using
install_github("cran/RandomFields") or
install_version("RandomFields", "3.3.14").

The issue that I am running into is with my C++ compiler. When I run either of the lines of code above, I get ERROR: compilation failed for package ‘RandomFields’:

> install_version("RandomFields", "3.3.13")
Downloading package from url: https://cran.rstudio.com//src/contrib/Archive/RandomFields/RandomFields_3.3.13.tar.gz
* installing *source* package ‘RandomFields’ ...
** package ‘RandomFields’ successfully unpacked and MD5 sums checked
** using staged installation
configure: creating ./config.status
config.status: creating src/Makevars
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RandomFieldsUtils/include' -I/usr/local/include     -fPIC  -Wall -g -O2  -c AutoRandomFields.cc -o AutoRandomFields.o
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RandomFieldsUtils/include' -I/usr/local/include     -fPIC  -Wall -g -O2  -c Brown.cc -o Brown.o

[lots of warnings generated...]

ld: warning: directory not found for option '-L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin18/8.2.0'
ld: warning: directory not found for option '-L/usr/local/gfortran/lib'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [RandomFields.so] Error 1
ERROR: compilation failed for package ‘RandomFields’
* removing ‘/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RandomFields’
Warning in i.p(...) :

I already have xtools installed and following this forum, am trying to set up gfortram. I have successfully installed homebrew (brew.sh/) on my computer, but when I try and run - brew install gcc on my terminal, I get the following:

error: Not a valid ref: refs/remotes/origin/master
fatal: ambiguous argument 'refs/remotes/origin/master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
Running `brew update --auto-update`...
fatal: Could not resolve HEAD to a revision
Warning: No available formula with the name "gcc".
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

My understanding is that gfortran is no longer provided separate of gcc, so you have to set up gcc first in order to set up gfortran but I don't know enough about coding in my terminal to know what to do now.

My main goal is to get the NLMR and RandomFields packages working on my computer, so if there is a way to do this without addressing the compiler issue, please let me know!

Session info:
I am running a macOS Monterey Version 12.3.1
R version 4.2.0 (2022-04-22)
RStudio Version 1.4.1725

Please let me know if I can clarify anything and thanks in advance for your time!

Scroll down to Tools and click on the "Tools page" link.

That is a rather old version of RStudio. I suggest updating to the latest release, 2022.02.2

Fantastic, thank you! This worked great :slight_smile:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.