[R-SIG-Mac] FLIBS for binary R installations (was library 'quadmath' not found)

Prof Brian Ripley r|p|ey @end|ng |rom @t@t@@ox@@c@uk
Sun May 26 09:42:40 CEST 2024


This is only about use of CRAN binary installations of R, and
specifically the arm64 build of R 4.4.0.  It is rather technical ... but
with a simple take-home message at the end.

Because CRAN binary distributions contain copies of the Fortran
runtime libraries there are a number of other possibilities.
The distributed etc/Makeconf contains

FLIBS =  -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0 
-L/opt/gfortran/lib -lgfortran -lemutls_w -lquadmath

(Only the arm64 version contains -lemutls_w: it is a static library so
only needed when compiling Fortran code, and probably only Fortran
code using OpenMP and that has to be linked by gfortran and so does not
use FLIBS.)

https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#macOS-packages
and
https://cran.r-project.org/doc/manuals/r-devel/R-admin.html#macOS-packages

describe how to override this, either personally (via ~/.R/Makevars)
or for all users (set R_MAKEVARS_SITE).

FLIBS is used when installing a package that contains Fortran source
code or links to Fortran libraries, most prominently BLAS and LAPACK
libraries.  The way linking works is rather different on macOS
from other platforms.


Scenarios
=========

a) If you want to compile a package from sources containing Fortran
code, you will need the recommended Fortran compiler and installing
that will match the FLIBS in the distribution. It will also work to
use

FLIBS = -L/Library/Frameworks/R.framework/Resources/lib -lgfortran 
-lquadmath

NB: a large majority of the Fortran-using packages do not make any calls 
to the Fortran runtime libraries, so any setting of FLIBS including 
empty will work provided it does not refer to non-existent paths.

If you use a different compiler (such as those for gfortran 13 or 14 
mentioned in the manual), you will need to set FLIBS appropriately but 
the above will probably do.


b) Compiling a package from source which calls BLAS or LAPACK but not 
Fortran will need to find the Fortran runtime libraries.  As the 
distributed BLAS and LAPACK libraries are already built against those 
included with R and hardcode their paths, you could also use

FLIBS =


c) Installing a CRAN binary package that uses Fortran source code.
This will have a .so linked against the Fortran libraries from the
CRAN binary R, e.g.

auk2% otool -L Hmisc/libs/Hmisc.so
Hmisc/libs/Hmisc.so:
	Hmisc.so (compatibility version 0.0.0, current version 0.0.0)
	/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libgfortran.5.dylib (compatibility version 6.0.0, current version 6.0.0)
	/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)
	/Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libR.dylib (compatibility version 4.4.0, current version 4.4.0)

So FLIBS is not used.  (Actually Hmisc is one of the many packages
with no calls to the Fortran runtime libraries.)

Ditto for a binary package which calls BLAS or LAPACK.

This may not be the case for binary packages from other repositories.


d) A very few packages compile a Fortran executable (cepreader,
x13binary, INLA).  As these are linked by gfortran, FLIBS is not used,
but the CRAN binary package for cepreader is linked against the paths
in the gfortran distribution so that is required.  For x13binary the
R-provided libs are used whereas INLA ships its own copies (but has
missed one).


It seems that life for those using binary builds would be simpler if
their etc/Makeconf contained

FLIBS = -L/Library/Frameworks/R.framework/Resources/lib -lgfortran 
-lquadmath

Until that is done, I recommend creating a ~/.R/Makevars file
containing that line.



On 23/05/2024 17:03, Prof Brian Ripley via R-SIG-Mac wrote:
> On 23/05/2024 16:00, Petar Milin wrote:
>> I have recently updated my R (4.4.0) and all the packages running on 
>> Sonoma (14.5) with Intel. When I try to install from GitHub with:
>>
>> install_github("zdk123/SpiecEasi")
>>
>> I get the error message:
>>
>> ld: warning: search path 
>> '/opt/gfortran/lib/gcc/x86_64-apple-darwin20.0/12.2.0' not found
>> ld: warning: search path '/opt/gfortran/lib' not found
>                 ^^^^ is the important message.
> 
>> ld: library 'quadmath' not found
>> clang: error: linker command failed with exit code 1 (use -v to see 
>> invocation)
>> make: *** [SpiecEasi.so] Error 1
>> ERROR: compilation failed for package ‘SpiecEasi’
>>
>> I did
>>
>> xcode-select –install
>>
>> but that was done already.
>>
>> I also installed
>>
>> gfortran-4.2.3.pkg
>>
>> but that did not help either.
> 
> Please remove it via pkgutils: it is way too old.
> 
>> Can anyone advise, please?
> 
> Please read the R-admin manual.  To install a package using Fortran from 
> sources you need to install 
> https://mac.r-project.org/tools/gfortran-12.2-universal.pkg, also 
> indicated via the tools page linked from 
> https://cran.r-project.org/bin/macosx/
> 
> 

-- 
Brian D. Ripley,                  ripley using stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford



More information about the R-SIG-Mac mailing list