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:
- Installed OSX 10.15.6
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.
- Ran into an issue trying to run some old
glmmTMB
models
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++.
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.
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.
- Installed Xcode to help set a baseline c++ environment
Relatively painless, am able to build and compile fairly simple c++ projects.
- Installed R 4.0.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.
- Followed @coatless's guide to installing Rcpp
Discovered this guide and followed each step, except for those related to xcode-select
.
- Testing Rcpp and RcppArmadillo from the guide
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.
- Tried to debug
Rcpp
to no avail
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.
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).
- Installing
glmmTMB
from source fails
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
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!
Edit 1
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:
Removed
gfortran 8.2
. Removed~/.Renviron
and~/.R/Makevars
. Unlinked both of these files from Rstudio withunlink()
.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 withsudo rm -rf /Library/Developer/CommandLineTools
and installed the Command Line Tools withxcode-select —install
. Up to this point everything is working as expected. Small c++ programs are being compiled without issue by bothgcc
andclang++
.According to the R manual, from
https://mac.r-project.org/libs-4/
, I installedpcre2-10.34-darwin.17-x86_64.tar.gz
,xz-5.2.4-darwin.17-x86_64.tar.gz
, andreadline-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.Restarted an R session in RStudio.
Installed Rcpp and RcppArmadillo with
install.packages(c(‘Rcpp’, ‘RcppArmadillo’))
Created a
~/helloworld.cpp
with the code from Slide 15 mentioned in the comments.Running
Rcpp::sourceCpp("~/helloworld.cpp")
fails with the exact error as mentioned in the body of the post. SimilarlyevalCpp()
fails with a similar error.