一系列更新后RCPP无法编译C ++代码 [英] Rcpp fails to compile c++ code after series of updates

查看:58
本文介绍了一系列更新后RCPP无法编译C ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使我的OS,R和R软件包保持最新.我不知不觉地通过升级到OSX 10.15.6和升级到R 4.0.2进入了深水区.当前, Rcpp 无法编译c ++代码,我认为这会导致某些软件包的CRAN安装失败(例如, glmmTMB ),并且还会导致从源代码安装到失败.我将描述自己的工作,并希望有人可以阐明解决方案.

I'd like to keep my OS, R, and R packages up to date. I unknowingly treaded into deep water by upgrading to OSX 10.15.6 and upgrading to R 4.0.2. Currently, Rcpp is failing to compile c++ code, which I believe is causing the CRAN installation for certain packages to fail (e.g. glmmTMB), and is also causing installations from source to fail. I'll describe what I've done and hopefully someone can elucidate a solution.

大致来说,这是我所做的:

In a rough order, here's what I've done:

  1. 已安装OSX 10.15.6

我不记得日期了,但是那是最近的日期.我不知道这与问题有多紧密,在安装其他需要 Rcpp 的R软件包(例如 rstan )时遇到了问题.

I don't remember the date but it was fairly recent. I don't know how closely this is related to the problem, I was having issues installing other R packages (e.g. rstan) that needed Rcpp prior to this.

  1. 遇到问题,试图运行一些旧的 glmmTMB 模型

确切的错误与此问题相同.我没有遵循该线程上的各种解决方案.也许最令人沮丧的是尝试从源代码安装时,然后无法编译某些c ++.

The exact error was identical to this issue. I followed the various solutions on that thread to no avail. Perhaps the most frustrating was when attempting to install from source, which then failed to compile some c++.

这不是我第一次看到类似的错误.当我尝试安装 rstan 时,发生了类似的事情,因此我在类似问题.没有任何帮助.

This wasn't the first time I had seen similar errors. Something similar happened when I tried installing rstan, so I asked for some help on their repo under a similar issue. Nothing helped.

这是在R 3.6上进行的,所以我认为也许值得更新R和 glmmTMB .在执行此操作之前,我想安装Xcode,而不是仅安装Command Line Developer Tools,希望该安装可以确保我将与clang和c ++编译器相关的所有信息都摆平.

This was on R 3.6, so I thought maybe it'd be worth updating R and glmmTMB. Before doing this I wanted to install Xcode, as opposed to just the Command Line Developer Tools, in hopes that the installation would ensure I'd have everything clang- and c++ compiler-related squared away.

  1. 安装了Xcode以帮助设置基准c ++环境

相对容易,能够构建和编译相当简单的c ++项目.

Relatively painless, am able to build and compile fairly simple c++ projects.

  1. 已安装R 4.0.2

我从r-project站点安装了R-4.0.2.pkg,没有问题,并且具有默认安装设置.根据 R项目工具网站所述,我对安装Xcode感到放心,并继续进行安装GNU Fortran 8.2安装程序.

From the r-project site, I installed R-4.0.2.pkg without issues and with the default install settings. According to the R project Tools site, I was reassured in installing Xcode and continued on to install the GNU Fortran 8.2 installer.

  1. 遵循@coatless安装Rcpp的指南

发现了本指南和除了与 xcode-select 相关的步骤外,其他步骤均遵循该步骤.

Discovered this guide and followed each step, except for those related to xcode-select.

  1. 从指南中测试Rcpp和RcppArmadillo

最后一步之一是使用简单的 helloworld.cpp 测试来测试安装.失败并显示此错误(为清楚起见,已删除):

One of the last steps is to test the installation with a simple helloworld.cpp test. This fails with this error (abridged for clarity):

> Rcpp::sourceCpp("~/Documents/BergenLab/nlp_cancer_metaphor/helloworld.cpp")
In file included from helloworld.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadillo.h:31:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include/RcppArmadilloForward.h:26:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/RcppCommon.h:29:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/r/headers.h:67:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:100:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [helloworld.o] Error 1
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I../inst/include   -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppArmadillo/include" -I"/Users/alex/Documents/BergenLab/nlp_cancer_metaphor" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include   -fPIC  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c helloworld.cpp -o helloworld.o
Error in Rcpp::sourceCpp("~/Documents/BergenLab/nlp_cancer_metaphor/helloworld.cpp") : 
  Error 1 occurred building shared library.

  1. 试图调试 Rcpp 无济于事

找到了一些相关的报告,例如由于以下原因,软件包无法从源构建找不到math.h ​​ Rcpp不在macOS下,找不到math.h 由于找不到math.h,源Cpp文件失败更新到macOS Catalina后无法使用c ++代码编译R软件包.

Found some somewhat related reports, such as Packages cannot build from source due to math.h not found, Rcpp doesn't under macOS, math.h not found, Source Cpp file failed due to math.h not found, and Cannot compile R packages with c++ code after updating to macOS Catalina.

这些答案中的所有解决方案都没有帮助.给我反馈的唯一解决方案是使用 installer 安装 macOS_SDK_headers_for_macOS_10.14.pkg ,随后又给了我 installer:错误-指定的软件包路径无效(不确定其含义是什么).

None of the solutions in these answers have helped at all. The only solution which gave me feedback was using installer to install macOS_SDK_headers_for_macOS_10.14.pkg which subsequently gave me installer: Error - the package path specified was invalid (not sure how what the implications of this are).

  1. 从源代码安装 glmmTMB 失败

上述 glmmTMB 问题中的一种解决方案建议从源代码进行安装.这是我尝试的错误:

One of the solutions from an above glmmTMB issue recommends installing from source. Here is the error on my attempt:

* installing *source* package ‘glmmTMB’ ...
** package ‘glmmTMB’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang++ -mmacosx-version-min=10.13 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include' -I'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include' -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include   -fPIC  -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c glmmTMB.cpp -o glmmTMB.o
In file included from glmmTMB.cpp:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/TMB/include/TMB.hpp:53:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Dense:1:
In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/RcppEigen/include/Eigen/Core:96:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:245:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error: no member named 'signbit' in the global namespace
using ::signbit;
      ~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
13 warnings and 20 errors generated.
make: *** [glmmTMB.o] Error 1
ERROR: compilation failed for package ‘glmmTMB’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/glmmTMB’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/glmmTMB’
Warning in install.packages :
  installation of package ‘glmmTMB’ had non-zero exit status


总体而言,我仍然无法运行我的 glmmTMB 模型(并且我也认为也无法构建 rstan ).我的c ++编译器上的某些东西必须关闭,但我是c ++初学者,不确定如何解释我得到的错误.头文件出了点​​问题,但似乎不是由于 math.h 丢失(与大多数其他帖子一样)引起的.应该不言而喻,但是任何帮助将不胜感激!


Overall, I'm still unable to run my glmmTMB models (and I presume unable to build rstan as well). Something with my c++ compiler must be off but I'm a c++ beginner and am unsure how to interpret the errors I'm getting. Something's wrong with the header files, but it seems perhaps like it's not due to math.h being missing (like most other posts). It should go without saying but any help would be greatly appreciated!

编辑1

我试图缩小错误的范围,并按照@coatless指南中的步骤进行操作,严格按照此处列出的内容以及根据R安装文档进行操作.我的确切步骤:

I've tried to narrow down the error and thus followed each step from @coatless's guide, exactly as listed there and according to the R installation documentation. My exact steps:

  1. 删除了 gfortran 8.2 .删除了〜/.Renviron 〜/.R/Makevars .使用 unlink()从Rstudio取消链接这两个文件.

  1. Removed gfortran 8.2. Removed ~/.Renviron and ~/.R/Makevars. Unlinked both of these files from Rstudio with unlink().

Ran xcode-select --install ,并返回使用"软件更新"安装更新."因此, softwareupdate --list 估计不需要更新.无论如何,我都使用 sudo rm -rf/Library/Developer/CommandLineTools 卸载了命令行工具,并使用 xcode-select —install 安装了命令行工具.到目前为止,一切都按预期进行.小型c ++程序正在由 gcc clang ++ 编译而没有问题.

Ran xcode-select --install, which returned with "use "Software Update" to install updates." Accordingly, softwareupdate --list estimated that nothing needed updating. Regardless, I uninstalled Command Line Tools with sudo rm -rf /Library/Developer/CommandLineTools and installed the Command Line Tools with xcode-select —install. Up to this point everything is working as expected. Small c++ programs are being compiled without issue by both gcc and clang++.

根据R手册,从 https://mac.r-project.org/libs-4/中,我安装了 pcre2-10.34-darwin.17-x86_64.tar.gz xz-5.2.4-darwin.17-x86_64.tar.gz readline-5.2.14-darwin.17-x86_64.tar.gz /usr/local .这里没有什么大问题,尽管我不确定如何验证这些功能是否可以正常工作.

According to the R manual, from https://mac.r-project.org/libs-4/, I installed pcre2-10.34-darwin.17-x86_64.tar.gz, xz-5.2.4-darwin.17-x86_64.tar.gz , and readline-5.2.14-darwin.17-x86_64.tar.gz to /usr/local. No big issues here, although I'm not really sure how to verify that these work as expected.

在RStudio中重新启动R会话.

Restarted an R session in RStudio.

使用 install.packages(c('Rcpp','RcppArmadillo'))

使用注释中提到的幻灯片15中的代码创建了一个〜/helloworld.cpp .

Created a ~/helloworld.cpp with the code from Slide 15 mentioned in the comments.

运行 Rcpp :: sourceCpp(〜/helloworld.cpp")失败,并出现帖子正文中提到的确切错误.类似地, evalCpp()失败,并显示类似错误.

Running Rcpp::sourceCpp("~/helloworld.cpp") fails with the exact error as mentioned in the body of the post. Similarly evalCpp() fails with a similar error.

推荐答案

经过一番挖掘后,问题根本不是 glmmTMB Rcpp 任何高级的.据我了解:当R使用 Rcpp 编译c ++代码时,某些参数集将传递给系统c ++编译器.就我而言,此编译器是clang ++,因为我刚刚安装了Xcode.C ++编译器依赖于一组 c ++头文件完全按照正确的顺序包含在它们中.似乎是我的顺序不正确,因此导致了一系列有关缺少模板定义"的错误.

After a bit of digging, the issue turned out to be neither glmmTMB, Rcpp, or really anything high-level. From what I understand: When R uses Rcpp to compile c++ code, a certain set of arguments are passed to the system c++ compiler. In my case this compiler was clang++ since I had just installed Xcode. The c++ compiler relies on a set of c++ header files to be included in exactly the right order. Seemed like the order of mine were incorrect, thus causing a slew of errors regarding "missing template definitions."

我研究了更改包含的顺序,但找不到任何直接的解决方案.我知道 Rcpp 正在调用clang ++的非常特定的参数数组,因此我研究了如何阐明答案.我查看了clang ++的手册,以了解 -isysroot -I 的含义,并认为它们可能在重新配置系统头文件的编译方式中发挥了作用.从下面的线程之一中,我发现了 $(R RHOME)/etc/Makeconf Makefile,然后将OSX SDK的目录从我认为的命令行工具路径更改为Xcode路径.这似乎解决了问题.

I looked into changing the order of the includes but couldn't find any straightforward solution. I knew that Rcpp was calling a very specific array of arguments to clang++, so I looked into how that might elucidate an answer. I looked into the manuals for clang++ to figure out what -isysroot and -I meant and felt like they might play a part in reconfiguring how the system header files were being compiled. From one of the threads below I discovered the $(R RHOME)/etc/Makeconf Makefile and proceeded to change the directory of the OSX SDK from what I believe was the Command Line Tools path to the Xcode path. This seemed to solve the issue.

一些我用来找到此解决方案的线程:

Some threads I used to find this solution: Cannot compile R packages with c++ code after updating to macOS Catalina and Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace.

什么对我有用:

  1. 注意当前的头文件搜索

clang ++ -Wp,-v -E-:

#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.3/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)

  1. 注意OSX SDK路径

xcrun --show-sdk-path :

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

  1. 修改R配置

使用 vim $ {R RHOME)/etc/Makeconf ,将 CPPFLAGS 标志更改为:

CPPFLAGS = -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include

请注意该SDK目录在步骤2中的位置.这显然清除了SDK头文件包含的位置和顺序.

Notice how this SDK directory is what was found in step 2. This apparently cleans up the location and order of the SDK header file includes.

  1. 从源代码中重新安装 glmmTMB

当尝试拟合 glmmTMB 模型时,我仍然看到 FreeADFunObject 错误,所以我回到了

I was still seeing a FreeADFunObject error when trying to fit a glmmTMB model, so I went back to this GH thread and followed the first suggestion: to reinstall from source. This wasn't working before since I needed a properly set up c++ configuration, which I fixed in the last two steps.

因此,已成功安装 install.packages("glmmTMB",type ="source"),现在我可以构建并安装 glmmTMB 模型.

Hence, install.packages("glmmTMB", type="source") installed without issue and I can now build and fit glmmTMB models.

为了后代的缘故:

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/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

这篇关于一系列更新后RCPP无法编译C ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆