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 - there shouldn't be 'undeclared identifier' errors coming from a CRAN package. I'm not sure how to fix the problem, though, and I wasn't able to find any examples online of others getting a similar message. I've seen a lot of similar errors online, but the fixes for those haven't helped me get around this isNull()
error.
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.
Initially, the compiler was unable to find the ICU4C library (which also prevented me from installing stringi
), but I was able to point pkg-config
to the library by running brew link icu4c --force
and that resolved it.
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.
My admittedly non-expert assumption is that this has to do with the compilers I've downloaded, the M1 architecture workarounds I've done, and/or my Makevars file, as I've installed stringi
on previous (older) Macbooks before without any issue.
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 usingHomebrew
& 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!