更新到 macOS Catalina 后,无法使用 c++ 代码编译 R 包



我刚刚更新到macOS Catalina,并尝试编译我正在开发的R包。但是,现在它不起作用。我不确定这是因为操作系统还是因为Rcpp包。任何帮助将不胜感激!

> devtools::load_all(".")
Loading phyr
Re-compiling phyr
─  installing *source* package ‘phyr’ ...
** using staged installation
** libs
/usr/local/clang4/bin/clang++ -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I"/Users/dli/R/Rcpp/include" -I"/Users/dli/R/RcppArmadillo/include" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include  -fPIC  -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
In file included from RcppExports.cpp:4:
In file included from /Users/dli/R/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Users/dli/R/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Users/dli/R/Rcpp/include/RcppCommon.h:29:
In file included from /Users/dli/R/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Users/dli/R/Rcpp/include/Rcpp/platform/compiler.h:100:
/usr/local/clang4/bin/../include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
using ::signbit;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:315:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
^
In file included from RcppExports.cpp:4:
In file included from /Users/dli/R/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Users/dli/R/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Users/dli/R/Rcpp/include/RcppCommon.h:29:
In file included from /Users/dli/R/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Users/dli/R/Rcpp/include/Rcpp/platform/compiler.h:100:
/usr/local/clang4/bin/../include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace
using ::isinf;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace
using ::isnan;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:319:9: error: no member named 'isgreater' in the global namespace
using ::isgreater;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:320:9: error: no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace
using ::isless;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
~~^
/usr/local/clang4/bin/../include/c++/v1/cmath:331:9: error: no member named 'abs' in the global namespace; did you mean 'fabs'?
using ::abs;
~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/math.h:417:15: note: 'fabs' declared here
extern double fabs(double);
^
In file included from RcppExports.cpp:4:
In file included from /Users/dli/R/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Users/dli/R/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Users/dli/R/Rcpp/include/RcppCommon.h:29:
In file included from /Users/dli/R/Rcpp/include/Rcpp/r/headers.h:59:
In file included from /Users/dli/R/Rcpp/include/Rcpp/platform/compiler.h:100:
/usr/local/clang4/bin/../include/c++/v1/cmath:557:28: error: expected a qualified name after 'typename'
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
^
/usr/local/clang4/bin/../include/c++/v1/cmath:557:37: error: expected ';' at end of declaration
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
^
/usr/local/clang4/bin/../include/c++/v1/cmath:557:37: error: expected unqualified-id
/usr/local/clang4/bin/../include/c++/v1/cmath:569:39: error: use of undeclared identifier 'is_floating_point'
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
^
/usr/local/clang4/bin/../include/c++/v1/cmath:569:57: error: '_A1' does not refer to a value
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
^
/usr/local/clang4/bin/../include/c++/v1/cmath:567:17: note: declared here
template <class _A1>
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [RcppExports.o] Error 1
ERROR: compilation failed for package ‘phyr’
─  removing ‘/private/var/folders/b0/zl5p7whd1zg4cwk9q1nc69_h0000gn/T/RtmpE8aUBf/devtools_install_2b457078750/phyr’
Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
System command error

这是我的会话信息。

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15
Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
loaded via a namespace (and not attached):
[1] Rcpp_1.0.2                compiler_3.6.1            prettyunits_1.0.2        
[4] remotes_2.1.0             tools_3.6.1               testthat_2.2.1           
[7] digest_0.6.21             pkgbuild_1.0.6            pkgload_1.0.2            
[10] memoise_1.1.0             nlme_3.1-140              lattice_0.20-38          
[13] mgcv_1.8-28               rlang_0.4.0               Matrix_1.2-17            
[16] cli_1.1.0                 rstudioapi_0.10           parallel_3.6.1           
[19] RcppArmadillo_0.9.700.2.0 withr_2.1.2               cluster_2.1.0            
[22] fs_1.3.1                  desc_1.2.0                devtools_2.2.1           
[25] rprojroot_1.3-2           grid_3.6.1                glue_1.3.1               
[28] R6_2.4.0                  processx_3.4.1            sessioninfo_1.1.1        
[31] callr_3.3.2               magrittr_1.5              backports_1.1.5          
[34] ps_1.3.0                  ellipsis_0.3.0            MASS_7.3-51.4            
[37] splines_3.6.1             usethis_1.5.1             assertthat_0.2.1         
[40] permute_0.9-5             picante_1.8               ape_5.3                  
[43] crayon_1.3.4              vegan_2.5-6              

谢谢!

您可能需要重新安装命令行工具 - Apple通常会在操作系统更新后卸载它们。尝试跑步:

xcode-select --install

在终端中。(请注意,即使您使用的是 R 提供的 LLVM 工具链,它仍然需要访问默认系统标头,并且这些标头作为命令行工具工具链的一部分安装(

编辑:@coatless是现场的。特别是,从 https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/开始,您需要将~/.R/Makevars设置为指向系统标头:

mkdir -p ~/.R
# Fill with appropriate flag statements
cat <<- EOF > ~/.R/Makevars
# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
# clang: end
EOF

请注意,默认情况下修补的 R 3.6.1 会这样做——例如,我在我的$(R RHOME)/etc/Makeconf中有:

CPPFLAGS = -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

请使用:

https://github.com/coatless/r-macos-rtools/releases/latest

或手动完成这些步骤:

https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/

此版本的 macOS 所需的主要更改是需要为标头位置设置标志,因为没有 SDK 工具包可用于重新安装到R的预期目录中。

最新更新