Unable to install stringi R package on macOS M1 Monterey

I have been unable to install the R package stringi on my Macbook Pro (running MacOS Monterey) with the new M1 & arm64 architecture. There are a number of posts on SO describing similar problems, but the error message I’m receiving is something I haven’t seen before.

When I run install.packages("stringi") in RStudio, I receive the following error message:

stri_brkiter.cpp:60:9: error: use of undeclared identifier
      'isNull'
    if (isNull(opts_brkiter)) {
        ^

I’m guessing there is some kind of compiler mismatch going on here, but I’m not sure what to make of that error message or how to fix the problem. I wasn’t able to find any examples online of others getting a similar message, either.

Note: The lines above are just the error portion of the message output. See below for full error text.

> install.packages("stringi")
Installing package into ‘/Users/<username>/r_libs’
(as ‘lib’ is unspecified)
Package which is only available in source form, and may need
  compilation of C/C++/Fortran: ‘stringi’
Do you want to attempt to install these from sources? (Yes/no/cancel) yes
installing the source package ‘stringi’

Content type 'application/x-gzip' length 7578882 bytes (7.2 MB)
==================================================
downloaded 7.2 MB

* installing *source* package ‘stringi’ ...
** package ‘stringi’ successfully unpacked and MD5 sums checked
** using staged installation
checking for R_HOME... /Library/Frameworks/R.framework/Resources
checking for R... /Library/Frameworks/R.framework/Resources/bin/R
checking for endianness... little
checking for R >= 3.1.0 for C++11 use... yes
checking for R < 3.4.0 for CXX1X flag use... no
checking for cat... /bin/cat
checking for local ICUDT_DIR... icu69/data
checking for gcc... clang -arch arm64
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether clang -arch arm64 accepts -g... yes
checking for clang -arch arm64 option to accept ISO C89... none needed
checking how to run the C preprocessor... clang -arch arm64 -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... rm: conftest.dSYM: is a directory
rm: conftest.dSYM: is a directory
yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking elf.h usability... no
checking elf.h presence... no
checking for elf.h... no
checking whether we are using the GNU C++ compiler... yes
checking whether clang++ -arch arm64 -std=gnu++11 accepts -g... yes
checking whether the C++ compiler supports the long long type... yes
checking whether the compiler implements namespaces... yes
checking whether the compiler supports Standard Template Library... yes
checking whether std::map is available... yes
checking for pkg-config... /opt/homebrew/bin/pkg-config
checking with pkg-config for the system ICU4C... 70.1
checking for ICU4C >= 55... yes
checking for additional required CPPFLAGS, LDFLAGS, and LIBS... done
checking whether an ICU4C-based project can be built... yes
checking programmatically for sufficient U_ICU_VERSION_MAJOR_NUM... yes
checking programmatically if U_CHARSET_IS_UTF8 is defined and set... yes
checking the capabilities of the ICU data library (ucnv, uloc, utrans)... yes
checking the capabilities of the ICU data library (ucol)... yes
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating src/uconfig_local.h
config.status: creating src/install.libs.R

*** stringi configure summary:
    ICU_FOUND=1
    STRINGI_CXXSTD=CXX_STD=CXX11
    STRINGI_CFLAGS=   -fPIC
    STRINGI_CPPFLAGS=-I. -I/opt/homebrew/Cellar/icu4c/70.1/include   -UDEBUG -DNDEBUG
    STRINGI_CXXFLAGS=   -fPIC
    STRINGI_LDFLAGS=-L/opt/homebrew/Cellar/icu4c/70.1/lib
    STRINGI_LIBS=-licui18n -licuuc -licudata

*** Compiler settings used:
    CC=clang -arch arm64
    LD=clang++ -arch arm64 -std=gnu++14
    CFLAGS=-falign-functions=64 -Wall -g -O2 -fPIC
    CPPFLAGS=-I/opt/R/arm64/include   -UDEBUG -DNDEBUG
    CXX=clang++ -arch arm64 -std=gnu++11
    CXXFLAGS=-falign-functions=64 -Wall -g -O2 -fPIC
    LDFLAGS=
    LIBS=

** libs
clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I. -I/opt/homebrew/Cellar/icu4c/70.1/include   -UDEBUG -DNDEBUG  -I/opt/R/arm64/include  -fPIC -fPIC  -falign-functions=64 -Wall -g -O2  -c stri_brkiter.cpp -o stri_brkiter.o
stri_brkiter.cpp:60:9: error: use of undeclared identifier
      'isNull'
    if (isNull(opts_brkiter)) {
        ^
stri_brkiter.cpp:130:9: error: use of undeclared identifier
      'isNull'
    if (isNull(opts_brkiter)) {
        ^
stri_brkiter.cpp:171:9: error: use of undeclared identifier
      'isNull'
    if (isNull(opts_brkiter)) {
        ^
3 errors generated.
make: *** [stri_brkiter.o] Error 1
ERROR: compilation failed for package ‘stringi’
* removing ‘/Users/<username>/r_libs/stringi’
* restoring previous ‘/Users/<username>/r_libs/stringi’

The downloaded source packages are in
    ‘/private/var/folders/qc/whkk090506v2qjy698yf25m80000gq/T/RtmpvLUDID/downloaded_packages’
Warning message:
In install.packages("stringi") :
  installation of package ‘stringi’ had non-zero exit status

I’ve tried installing stringi Both in R Studio and on the command line, which some SO posts suggested may be more effective, but I receive the same errors via both methods.

Other commands I’ve tried (that did NOT fix it):

install.packages('stringi', configure.args="--disable-cxx11")
install.packages("stringi", configure.args = "--with-extra-cxxflags="--std=c++11"")

Fully removing my Makevars file didn’t resolve the issue.

I’ve checked many of the major/popular related questions on SO & Github (including this, this, this, this, this etc). I think I’ve reached the edge of my understanding of this stuff, though, and I’m not really sure what I could try next.

System info:

  • OS: Mac OS Monterey (v 12.2) w/ an Apple M1 Max chip
  • R: R version 4.2.0
  • RStudio: RStudio version 1.4.1717
  • Xcode: Xcode version 13.3.1
  • Installed gcc/gfortran and other libraries using Homebrew & added download location to $PATH

My Makevars file:

This file was built based on advice from here, here, here, and here.

CC=/opt/homebrew/bin/gcc-11
CXX=/opt/homebrew/bin/g++-11

FC=/opt/homebrew/bin/gfortran-11
F77=/opt/homebrew/bin/gfortran-11
FLIBS=-L/opt/homebrew/opt/gfortran/lib -lgfortran -lquadmath -lm

CFLAGS=-I/opt/homebrew/include
CXXFLAGS=-O3 -Wall -pipe -Wno-unused -pedantic
CXX11FLAGS=-O3 -Wall -pipe -Wno-unused -pedantic

Does this error look familiar to anyone, or does anyone have suggestions of what I could do next to fix this? I’ve tried a lot of workarounds so I apologize if I’ve left anything out, please let me know if any other information could be useful!

Thanks!

Leave a Comment