You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacOS M1 Monterey安装R包stringi报isNull未声明编译错误

M1芯片MacOS环境下源码编译R包stringi报isNull未声明错误排查

运行环境

  • 设备:搭载Apple M1 Max芯片的MacBook Pro
  • 系统:MacOS Monterey 12.2
  • 软件环境:R 4.2.0、RStudio 1.4.1717、Xcode 13.3.1
  • 依赖配置:已通过Homebrew安装gcc/gfortran等编译依赖,并将安装路径添加至$PATH环境变量

问题描述

执行install.packages("stringi")安装R包stringi时,在源码编译阶段抛出异常。Stack Overflow已有大量同包安装问题帖,但本次遇到的报错暂未检索到匹配的解决方案记录。
核心报错信息如下:

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

初步判断问题由编译器不匹配导致——CRAN官方发布的正式包理论上不应出现未声明标识符类的基础编译错误。前期编译时曾遇到ICU4C库找不到的问题,已通过执行brew link icu4c --force配置pkg-config路径解决,后续尝试所有公开的通用stringi安装修复方案均无法解决该isNull()报错,且在RStudio图形界面、命令行R环境两种场景下安装报错完全一致。非M1架构的旧款MacBook设备上安装同版本stringi从未遇到同类问题,推测问题与M1架构下的编译器配置、适配规则或Makevars文件设置有关。

已尝试的无效修复方案

  • 执行禁用C++11的安装命令:
    install.packages('stringi', configure.args='--disable-cxx11')
    
  • 执行强制指定C++11标准的安装命令:
    install.packages("stringi", configure.args = "--with-extra-cxxflags='--std=c++11'")
    
  • 完全删除本地Makevars配置文件后重新安装

完整安装报错日志

> 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

当前本地Makevars配置

参考公开的M1架构R环境适配教程编写的~/.R/Makevars内容如下:

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

求助需求

需要该报错的排查思路与可行修复方案,如需补充其他环境信息可随时告知。


内容的提问来源于stack exchange,提问作者Amanda Hiser

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.01 02:42:28