On macOS 13.4.1 (Ventura), I'm trying to compile R from source, but it doesn't find pcre2.h
even if I have installed it:
cd /tmp
export R_VERSION=4.2.3
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
./configure --prefix=/opt/R/${R_VERSION} \
--enable-R-shlib \
--enable-memory-profiling
R is now configured for aarch64-apple-darwin22.5.0
Source directory: .
Installation directory: /opt/R/4.2.3
C compiler: gcc -g -O2
Fortran fixed-form compiler: gfortran -fno-optimize-sibling-calls -g -O2
Default C++ compiler: g++ -std=gnu++14 -g -O2
C++11 compiler: g++ -std=gnu++11 -g -O2
C++14 compiler: g++ -std=gnu++14 -g -O2
C++17 compiler: g++ -std=gnu++17 -g -O2
C++20 compiler: g++ -std=gnu++20 -g -O2
Fortran free-form compiler: gfortran -fno-optimize-sibling-calls -g -O2
Obj-C compiler: gcc -g -O2 -fobjc-exceptions
Interfaces supported: X11, aqua, tcltk
External libraries: pcre2, readline, curl
Additional capabilities: NLS, ICU
Options enabled: shared R library, shared BLAS, R profiling, memory profiling
Capabilities skipped: PNG, JPEG, TIFF, cairo
Options not enabled:
Recommended packages: yes
Then
sudo make
Fails because :
grep.c:73:10: fatal error: 'pcre2.h' file not found
# include<pcre2.h>
^~~~~~~~~
1 error generated.
make[3]: *** [grep.o] Error 1
make[2]: *** [R] Error 2
make[1]: *** [R] Error 1
make: *** [R] Error 1
pcre2
have been installed, using homebrew :
brew install pcre2
Warning: pcre2 10.42 is already installed and up-to-date.
To reinstall 10.42, run:
brew reinstall pcre2
I can find the pcre2.h
here:
ls /opt/homebrew/include | grep pcre
pcre2.h
pcre2posix.h
How do I tell R to use /opt/homebrew/include for pcre2.h
?
If you look at that file it has a few #define
statements around it:
#ifdef HAVE_PCRE2
/* PCRE2_CODE_UNIT_WIDTH is defined to 8 via config.h */
# include<pcre2.h>
#else
/*
Some systems might have pcre headers in a subdirectory -- not seen recently.
*/
# ifdef HAVE_PCRE_PCRE_H
# include <pcre/pcre.h>
# else
# include <pcre.h>
# endif
#endif
And pcre is funny because there is the newer pcre2 and the older (!!) pcre3. I suggest you a) check what configure
produced, specifically in config.h
. And maybe b) check the current source version 4.3.1 as well as the current dev version. Lastly, Kurt is quite masterful in his use of autoconf
and m4
so you can trace the detection code.
For what it is worth, in the 25+ years I looked after Debian's builds of R (plus some initially helping the then-maintainer) I have not had issues.
PS Also note that ./configure
hass two flags for pcre you could consider. Worst case you can turn pcre2
off:
--with-pcre2 use PCRE2 library (if available) [yes]
--with-pcre1 use PCRE1 library (if available and PCRE2 is not)
[yes]
where pcre1
is probably ancient.