MacOS Big Sur x86_64环境下R devtools安装bandle包编译错误求助
R包bandle安装编译报错排查求助
我尝试使用如下命令安装R包:
devtools::install_github('ococrook/bandle')
运行过程中持续出现编译问题,返回大量报错,首先是与BH依赖相关的报错:
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include' -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -Wall -pedantic -fdiagnostics-color=always -c Bessel2ndKind.cpp -o Bessel2ndKind.o In file included from Bessel2ndKind.cpp:1: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadillo.h:34: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp.h:59: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/exceptions_impl.h:38: In file included from /usr/local/include/execinfo.h:28: /usr/local/include/os/base.h:274:37: warning: type nullability specifier '_Nullable' is a Clang extension [-Wnullability-extension] typedef void (*os_function_t)(void *_Nullable); ^ Bessel2ndKind.cpp:621:55: warning: explicitly assigning value of variable of type 'int' to itself [-Wself-assign] nk, tau, D = D, j + 1, nu).t(); ~ ^ ~ Bessel2ndKind.cpp:774:49: warning: explicitly assigning value of variable of type 'int' to itself [-Wself-assign] nk, tau, D = D, j + 1).t(); ~ ^ ~ In file included from Bessel2ndKind.cpp:2: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include/boost/math/special_functions/bessel.hpp:24: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include/boost/math/special_functions/detail/bessel_ik.hpp:97:18: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value] BOOST_ASSERT(abs(x) <= 2); ^ /Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include/boost/math/special_functions/detail/bessel_ik.hpp:366:9: note: in instantiation of function template specialization 'boost::math::detail::temme_ik<long double, boost::math::policies::policy<detail::forwarding_arg1, detail::forwarding_arg2>>' requested here temme_ik(u, x, &Ku, &Ku1, pol); // Temme series ^ /Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include/boost/math/special_functions/bessel.hpp:246:4: note: in instantiation of function template specialization 'boost::math::detail::bessel_ik<long double, boost::math::policies::policy<detail::forwarding_arg1, detail::forwarding_arg2>>' requested here bessel_ik(v, x, &I, &K, need_k, pol); ^ /Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include/boost/math/special_functions/bessel.hpp:258:11: note: in instantiation of function template specialization 'boost::math::detail::cyl_bessel_k_imp<long double, boost::math::policies::policy<detail::forwarding_arg1, detail::forwarding_arg2>>' requested here return cyl_bessel_k_imp(v, x, bessel_no_int_tag(), pol); ^
其次是与RcppArmadillo相关的报错:
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include' -I'/Library/Frameworks/R.framework/Versions/4.1/Resources/library/BH/include' -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -Wall -g -O2 -Wall -pedantic -fdiagnostics-color=always -c leapfrogGPcpp.cpp -o leapfrogGPcpp.o In file included from leapfrogGPcpp.cpp:1: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadillo.h:34: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp.h:59: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include/Rcpp/exceptions_impl.h:38: In file included from /usr/local/include/execinfo.h:28: /usr/local/include/os/base.h:274:37: warning: type nullability specifier '_Nullable' is a Clang extension [-Wnullability-extension] typedef void (*os_function_t)(void *_Nullable); ^ In file included from leapfrogGPcpp.cpp:1: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:49: In file included from /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/armadillo:646: /Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppArmadillo/include/armadillo_bits/op_inv_meat.hpp:200:28: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value] const T abs_det_val = std::abs(det_val);
我已尝试多个公开解决方案,均未解决问题,暂无其他排查思路,恳请各位提供帮助,非常感谢。
解决步骤
你遇到的是macOS环境下R编译C++源码包的典型版本兼容问题,按以下步骤操作即可解决:
- 第一步:确认R版本和芯片架构匹配:如果是M1/M2等Apple Silicon芯片,不要使用Rosetta转译的x86版R,直接安装ARM架构的官方R安装包
- 第二步:更新所有核心编译依赖到最新版本,在R控制台运行:
install.packages(c("BH", "Rcpp", "RcppArmadillo"), type = "source")
- 第三步:调整macOS的R编译配置,在用户根目录下新建
.R/Makevars文件,写入以下内容:
CXX_STD = CXX11 CXXFLAGS += -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include LDFLAGS += -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib
如果是Apple Silicon芯片,额外追加一行配置:
FLIBS = -L/opt/homebrew/opt/gfortran/lib/gcc/current -lgfortran -lquadmath -lm
- 第四步:重启R会话,重新运行bandle的安装命令即可。
内容的提问来源于stack exchange,提问作者Isaac
相关产品推荐
相关产品推荐

