rstudio / httpuv

HTTP and WebSocket server package for R
Other
227 stars 86 forks source link

Compiling Error R 4.0.5 macOS Big Sur 10.16 and {renv} #301

Closed baggiponte closed 3 years ago

baggiponte commented 3 years ago

Problem

Hello! I am using R 4.0.5 on macOS Big Sur 10.16 (am using Homebrew as package manager) and I am trying to update the packages of a {renv} environment. Among these, there is {httpuv} which requires updating from 1.6.0 -> 1.6.1. However, the following error appears:

[...]
** R
** demo
** byte-compile and prepare package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Users/luca/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin20.3.0/Rcpp/1.0.6/dbb5e436998a7eba5a9d682060533338/Rcpp/libs/Rcpp.so':
  dlopen(/Users/luca/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin20.3.0/Rcpp/1.0.6/dbb5e436998a7eba5a9d682060533338/Rcpp/libs/Rcpp.so, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/10/libstdc++.6.dylib
  Referenced from: /Users/luca/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin20.3.0/Rcpp/1.0.6/dbb5e436998a7eba5a9d682060533338/Rcpp/libs/Rcpp.so
  Reason: image not found
Calls: <Anonymous> ... asNamespace -> loadNamespace -> library.dynam -> dyn.load
Execution halted
ERROR: lazy loading failed for package ‘httpuv’

What I tried

First, I tried to regularly compile it with g++ 11, the latest version I have installed. Then I installed g++ 10 and tried with that. To do so, I edited my .r/Makevars to look like this:

CC=clang
#CXX=clang++
#CXX=/usr/local/opt/gcc/bin/g++-11
CXX=/usr/local/opt/gcc@10/bin/g++-10

In this way I could use g++-10, but this did not change anything.

Since the error message says unable to load shared object '/Users/luca/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin20.3.0/Rcpp/1.0.6/dbb5e436998a7eba5a9d682060533338/Rcpp/libs/Rcpp.so':, I attached Rcpp and tried to install it again, to no avail.

I also tried to install the dev version with `renv::install('rstudio/httpuv') but the same problem occurred. Perhaps @kevinushey has something to say about it?

Thanks!

Session Info

My sessionInfo() is:

R version 4.0.5 (2021-03-31)
Platform: x86_64-apple-darwin20.3.0 (64-bit)
Running under: macOS Big Sur 10.16

Matrix products: default
LAPACK: /usr/local/Cellar/r/4.0.5_1/lib/R/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
 [1] tidyr_1.1.3       arrow_4.0.0.1     assertthat_0.2.1 
 [4] digest_0.6.27     utf8_1.2.1        R6_2.5.0         
 [7] repr_1.1.3        backports_1.2.1   evaluate_0.14    
[10] ggplot2_3.3.3     pillar_1.6.0      rlang_0.4.11     
[13] rmarkdown_2.8     stringr_1.4.0     bit_4.0.4        
[16] munsell_0.5.0     broom_0.7.6       compiler_4.0.5   
[19] xfun_0.22         pkgconfig_2.0.3   base64enc_0.1-3  
[22] htmltools_0.5.1.1 tidyselect_1.1.1  tibble_3.1.1     
[25] fansi_0.4.2       crayon_1.4.1      dplyr_1.0.6      
[28] grid_4.0.5        jsonlite_1.7.2    gtable_0.3.0     
[31] lifecycle_1.0.0   DBI_1.1.1         magrittr_2.0.1   
[34] scales_1.1.1      stringi_1.6.1     renv_0.13.2      
[37] skimr_2.1.3       ellipsis_0.3.2    generics_0.1.0   
[40] vctrs_0.3.8       tools_4.0.5       forcats_0.5.1    
[43] bit64_4.0.5       glue_1.4.2        purrr_0.3.4      
[46] yaml_2.2.1        colorspace_2.0-1  knitr_1.33  
kevinushey commented 3 years ago

Based on this error:

dlopen(/Users/luca/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin20.3.0/Rcpp/1.0.6/dbb5e436998a7eba5a9d682060533338/Rcpp/libs/Rcpp.so, 6): Library not loaded: /usr/local/opt/gcc/lib/gcc/10/libstdc++.6.dylib

Does this library (/usr/local/opt/gcc/lib/gcc/10/libstdc++.6.dylib) still exist, or was it removed when you updated gcc? I suspect it's gone now since /usr/local/opt normally only contains the "current" version of a particular Homebrew package.

You could probably fix this with install_name_tool; e.g. with something like:

install_name_tool -change \
    /usr/local/opt/gcc/lib/gcc/10/libstdc++.6.dylib \
    /usr/local/opt/gcc/lib/gcc/11/libstdc++.6.dylib \
    /Users/luca/Library/Application Support/renv/cache/v5/R-4.0/x86_64-apple-darwin20.3.0/Rcpp/1.0.6/dbb5e436998a7eba5a9d682060533338/Rcpp/libs/Rcpp.so

(alternatively, use install_name_tool to fix the library path to wherever gcc@10 lives in your /usr/local/Cellar directory) But this would likely need to be done for any package that had been installed with an older version of gcc.

kevinushey commented 3 years ago

FWIW, my understanding is that the Homebrew solution to this issue is to force any dependent packages to be rebuilt and reinstalled when gcc is updated, so one could argue this also applies transitively to any installed R packages as well (if you're using Homebrew gcc + Homebrew R).

baggiponte commented 3 years ago

Hi @kevinushey, thank you for your time and detailed answer!

I suspect it's gone now since /usr/local/opt normally only contains the "current" version of a particular Homebrew package.

Your suspects are correct!

In the end I just uninstalled r and reinstalled it. As Homebrew says:

The R Project provides official binaries: brew install --cask r Alternatively, the Homebrew-compiled version of R omits the GUI app: brew install r

Of course, I had installed the Homebrew-compiled one (which everybody seems to be using, tbh). It was brutal, indeed. But I could not even load some libraries (I tried to library(tidyverse) and it spat out an error message) and now everything works (also thanks to a famous Stackoverflow answer you gave about gfortran).

I am not sure if this will be useful to anyone someday. It is clear it had nothing to do with httpuv in the first place - perhaps it was sourced by updating r to 4.0.5 and incidentally by {renv}.