[R-SIG-Mac] configure: error: "liblzma library and headers are required"

1,139 views
Skip to first unread message

Marius Hofert

unread,
Jun 11, 2022, 9:53:06 AM6/11/22
to r-si...@r-project.org
Hi,

I'd like to install R from source on a MacBook Pro 14 (M1 Pro Max) and do that
for the first time under Apple Silicon. I could install all preliminaries from
source as I normally did under Intel Macs (even tcl and tk, gsl, gmp, mpfr, etc.).
However, the configure step of R fails with:

...
checking for lzma_version_number in -llzma... yes
checking for lzma.h... no
configure: error: "liblzma library and headers are required"

Related to this problem, I found the references below. However, none of the
suggested solutions worked for me.

The problem seems to be the installation of xz (and, as the references suggest, a similar
problem will arise from pcre2). The header file lzma.h is not found.

Here are the things I tried:

1) A plain 'brew install xz'.

2) Adding the directories where lzma.h is found to PATH:
/usr/local/bin/xz/include/lzma.h
/opt/R/arm64/include/lzma.h
/opt/homebrew/include/lzma.h
/opt/homebrew/Cellar/xz/5.2.5/include/lzma.h

3) Following https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Native-builds:
3.1) Creating /opt/R/arm64
3.2) Downloading xz-5.2.5-darwin.20-arm64.tar.xz from https://mac.r-project.org/bin/darwin20/arm64/
and unpacking it to /opt/R/arm64
3.3) Adding /opt/R/arm64 to PATH

How can xz be installed in Apple Silicon so that configure finds it including headers?

Let me know if you need more information.

Thanks & cheers,
Marius

References:
https://groups.google.com/g/r-sig-mac/c/UPPDNxn7ab4
https://cran.r-project.org/doc/manuals/r-release/R-admin.html#Prerequisites
https://mac.r-project.org/bin/darwin20/arm64/
https://www.mail-archive.com/r-si...@r-project.org/msg05844.html
https://stackoverflow.com/questions/40222371/install-r-with-shared-library-in-osx-liblzma-library-missing
https://pj.freefaculty.org/blog/?p=315






_______________________________________________
R-SIG-Mac mailing list
R-SI...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Simon Urbanek

unread,
Jun 11, 2022, 7:29:28 PM6/11/22
to Marius Hofert, r-si...@r-project.org
Marius,

most package systems (ours as well as Homebrew) don't use /usr/local on arm64 to not cause inadvertent conflicts with x86_64 binaries, so they must be explicitly added to flags. You failed to provide any details, but I suspect you didn't configure R to use whichever location is necessary for the dependencies since only /usr/local is searched by default. The flags used by CRAN can be seen at
https://svn.r-project.org/R-dev-web/trunk/QA/Simon/R4/conf.big-sur-arm64
which works for the binaries installed using

source("https://mac.R-project.org/bin/install.R")
install.libs("r-base-dev")

(Tcl/TK is not included, if needed you can install it from the release package).

Note that PATH has nothing to do with locating libraries by dyld - PATH is only used for executables so your $LOCAL/bin has to be on the PATH for pkg-config. Also note that mixing different systems is prone to cause chaos, because static and dynamic libraries have different precedence. So make sure you pick one choice (CRAN or Homebrew or Macport etc.) and stick with it.

Cheers,
Simon

Marius Hofert

unread,
Jun 11, 2022, 8:26:41 PM6/11/22
to Simon Urbanek, r-si...@r-project.org
Hi Simon,

thanks a lot for your help. I have to admit, a lot of what you wrote is entirely
new to me (probably because we are on arm64 now). So far, on Intel Macs, I
always could easily install R from source (see below) and thus had several
versions available, my own starter script, version-independent library of R
packages, etc. I used to use /usr/local/R for all of that (see below), which,
now will be /opt/R/arm64 I assume. However, I don't understand why suddenly
lzma.h is not found (even though it's inside /opt/R/arm64 as recommended and
also xz is found, etc.).

1) You mentioned "The flags used by CRAN... which works for the binaries
installed using source(...)". This part I don't understand. If you already have
R running (to be able to execute the source(); install.libs() command), why are
the flags for compiling R relevant?

2) Concerning the flags on
https://svn.r-project.org/R-dev-web/trunk/QA/Simon/R4/conf.big-sur-arm64, are
these the flags used per default if I do ./configure on arm64 or does it mean
that I need to provide all those flags on arm64 because they are not the
default?

3) The install.R script you mentioned already needs to be execute from R, so you
assume R is already installed. Is the recommended way then to install R via
binaries and then to use install.R to install the tools required to build
packages from source? Can you then still have various R versions installed
(and if so, where are they located)?

As a clarification, what I always did on Intel Macs and what I also tried now is this:

1) Install all preliminaries (GCC, Fortran, XQuartz, qpdf, Tcl/Tk, Open MPI,
GSL, GMP, MPFR, Java, XML, PCRE2, xz) either via brew or directly from source
(./configure, make, make install)

2) create /usr/local/R for the various R versions and ./usr/local/R/library for
a version-independent library of packages

3) Download R versions, say R-4.2.0.tar.gz and unpack them to /usr/local/R/R-4.2.0_source

4) Create /usr/local/R/R-4.2.0_build and execute:
export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig
../R-4.2.0_source/configure --enable-R-shlib --with-tcl-config=/Library/Frameworks/Tcl.framework/Versions/8.6/tclConfig.sh --with-tk-config=/Library/Frameworks/Tk.framework/tkConfig.sh

The latter configure step produced the lzma.h error described. Given what you wrote
I assume I failed to specify the location of the dependencies in ./configure. So
would the right ./configure then specify all flags provided by https://svn.r-project.org/R-dev-web/trunk/QA/Simon/R4/conf.big-sur-arm64 ?


Thanks again for your help & cheers,
Marius

________________________________________
From: Simon Urbanek <simon....@R-project.org>
Sent: Saturday, June 11, 2022 19:29
To: Marius Hofert
Cc: r-si...@r-project.org
Subject: Re: [R-SIG-Mac] configure: error: "liblzma library and headers are required"

Simon Urbanek

unread,
Jun 12, 2022, 2:45:05 AM6/12/22
to Marius Hofert, r-si...@r-project.org
Marius,

first, we can only guess since you failed to provide any details (no config.log etc.).

But to recap, R requires additional libraries that are not in the system, so it is your responsibility to provide them. How you do it is entirely up to you, there are many ways. However, if you put those libraries anywhere else than /usr/local then you have to set additional flags which will allow both the compiler and linker to find the new location, because Apple compilers only look in /usr (SDK) and in /usr/local. Given that both Homebrew and our binaries do not live in /usr/local for reasons I explained both *require* that you add the corresponding flags - which I suspect you may have failed to do.

Again, as I was saying my previous e-mail, if you use our static binaries in /opt/R/arm64 then you have add at the very least 'LDFLAGS=-L/opt/R/arm64/lib' 'CPPFLAGS=-I/opt/R/arm64/include' otherwise the compiler has no way of knowing where you put the libraries. In that case I would recommend using the other flags I listed as well unless you have strong reasons no to (especially given the Fortran idiosyncrasies on arm64).

As for install.libs() - that is merely a convenience function that gives you the list of libraries that are required to replicate the CRAN setup. It is not required - you can simply download and install the packages by hand if you wish. You can also simply use recipes to build those libraries yourself (just run scripts/build.sh r-base-dev), or an other system - it's entirely up to you. In the end R doesn't care as long as you provide working libraries and tell R where to find them.

Marius Hofert

unread,
Jun 13, 2022, 6:24:21 PM6/13/22
to Simon Urbanek, r-si...@r-project.org
Hi Simon,

thanks very much for your help. I now read a bit more about the "binaries way" of doing things and went with ./build.sh r-base-dev. Everything worked flawlessly. If I'm brave I will try again installing from source next time (with all the flags you mentioned) but for now I'm glad everything seems to run again :-)

Thanks & cheers,
Marius





________________________________________
From: Simon Urbanek <simon....@R-project.org>
Sent: Sunday, June 12, 2022 02:44
Reply all
Reply to author
Forward
0 new messages