YMa-lab / CARD

GNU General Public License v3.0
94 stars 21 forks source link

Error Installing on Mac Monterey M1 #52

Closed jamesboot closed 7 months ago

jamesboot commented 1 year ago

Hi,

Thanks for a great package. I am receiving the following error when installing:

> devtools::install_github('YingMa0107/CARD')
Downloading GitHub repo YingMa0107/CARD@HEAD
These packages have more recent versions available.
It is recommended to update all of them.
Which would you like to update?

 1: All                                       
 2: CRAN packages only                        
 3: None                                      
 4: digest       (0.6.32  -> 0.6.33   ) [CRAN]
 5: Rcpp         (1.0.10  -> 1.0.11   ) [CRAN]
 6: cpp11        (0.4.3   -> 0.4.5    ) [CRAN]
 7: jsonlite     (1.8.5   -> 1.8.7    ) [CRAN]
 8: MatrixModels (0.5-1   -> 0.5-2    ) [CRAN]
 9: spatstat.... (3.2-1   -> 3.2-4    ) [CRAN]
10: BiocManager  (1.30.21 -> 1.30.21.1) [CRAN]
11: sf           (1.0-13  -> 1.0-14   ) [CRAN]
12: V8           (4.3.0   -> 4.3.3    ) [CRAN]
13: viridis      (0.6.3   -> 0.6.4    ) [CRAN]
14: quantreg     (5.95    -> 5.96     ) [CRAN]

Enter one or more numbers, or an empty line to skip updates: 3
── R CMD build ─────────────────────────────────────────────────────────────────────────────────────────────────────────
✔  checking for file ‘/private/var/folders/kb/43q118t50tn_nf4ctrlp3t240000gn/T/Rtmpek3lgA/remotes1859632787ede/YingMa0107-CARD-4b674ab/DESCRIPTION’ ...
─  preparing ‘CARD’:
✔  checking DESCRIPTION meta-information ...
─  cleaning src
─  installing the package to process help pages
         -----------------------------------
─  installing *source* package ‘CARD’ ...
   ** using staged installation
   ** libs
   g++  -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppArmadillo/include' -I/usr/local/include    -fPIC  -Wall -g -O2  -Wall -pedantic -fdiagnostics-color=always -c CARDfree.cpp -o CARDfree.o
   g++  -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppArmadillo/include' -I/usr/local/include    -fPIC  -Wall -g -O2  -Wall -pedantic -fdiagnostics-color=always -c CARDref.cpp -o CARDref.o
   g++  -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG  -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2/Resources/library/RcppArmadillo/include' -I/usr/local/include    -fPIC  -Wall -g -O2  -Wall -pedantic -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o
   g++ -std=gnu++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o CARD.so CARDfree.o CARDref.o RcppExports.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/usr/local/gfortran/lib/gcc/aarch64-apple-darwin21/12.1.0 -L/usr/local/gfortran/lib -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
   ld: warning: -undefined dynamic_lookup may not work with chained fixups
   ld: warning: ignoring file /Library/Frameworks/R.framework/R, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
   ld: warning: ignoring file /Library/Frameworks/R.framework/Resources/lib/libRlapack.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
   ld: warning: ignoring file /Library/Frameworks/R.framework/Resources/lib/libRblas.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
   installing to /private/var/folders/kb/43q118t50tn_nf4ctrlp3t240000gn/T/Rtmpvm7asH/Rinst1863c4150c9e1/00LOCK-CARD/00new/CARD/libs
   ** R
   ** data
   ** byte-compile and prepare package for lazy loading
   Warning: replacing previous import ‘RcppML::nmf’ by ‘NMF::nmf’ when loading ‘CARD’
   ** help
   *** installing help indices
   ** building package indices
   ** installing vignettes
   ** testing if installed package can be loaded from temporary location
   Warning: replacing previous import ‘RcppML::nmf’ by ‘NMF::nmf’ when loading ‘CARD’
   Error: package or namespace load failed for ‘CARD’ in dyn.load(file, DLLpath = DLLpath, ...):
    unable to load shared object '/private/var/folders/kb/43q118t50tn_nf4ctrlp3t240000gn/T/Rtmpvm7asH/Rinst1863c4150c9e1/00LOCK-CARD/00new/CARD/libs/CARD.so':
     dlopen(/private/var/folders/kb/43q118t50tn_nf4ctrlp3t240000gn/T/Rtmpvm7asH/Rinst1863c4150c9e1/00LOCK-CARD/00new/CARD/libs/CARD.so, 0x0006): tried: '/private/var/folders/kb/43q118t50tn_nf4ctrlp3t240000gn/T/Rtmpvm7asH/Rinst1863c4150c9e1/00LOCK-CARD/00new/CARD/libs/CARD.so' (mach-o file, but is an incompatible architecture (have (arm64), need (x86_64)))
   Error: loading failed
   Execution halted
   ERROR: loading failed
─  removing ‘/private/var/folders/kb/43q118t50tn_nf4ctrlp3t240000gn/T/Rtmpvm7asH/Rinst1863c4150c9e1/CARD’
         -----------------------------------
   ERROR: package installation failed
Error: Failed to install 'CARD' from GitHub:
  ! System command 'R' failed

I read previous threads regarding the gcc compiler not being installed but I have installed it, seems to be working. Any suggestions would be great!

YingMa0107 commented 1 year ago

Hi @jamesboot,

Thank you for your interest in CARD!

It seems like the problem arises due to an architecture mismatch. The system you're using is arm64 (likely a newer Mac with the M1 chip), but the libraries that R is trying to link against were built for the x86_64 architecture (Intel Macs).

Here are a couple of things that you may try to fix this:

1. Update R and R packages:

Before proceeding, make sure you have the latest version of R installed on your macOS system. Additionally, update all the packages listed in the error message to their most recent versions. To do this, enter the numbers corresponding to the packages that need updates when prompted (e.g., enter '1' to update all packages).

2. Configure R to use x86_64 architecture:

If updating R and packages doesn't work, you can try running R in Rosetta2 mode, which allows it to use the x86_64 architecture on an arm64 macOS system. To do this, find R in Finder, Get Info on the app (right-click > Get Info), and check the box for "Open using Rosetta".

Hope this can help!

Best, Ying

jamesboot commented 1 year ago

Thanks Ying,

I have tried running R using Rosetta. It has helped to come extent, I have managed to install all of the dependencies and update the required packages. However when I try to install CARD I am still getting the above message even though I am running the x86_64 architecture.

Cheers James

YingMa0107 commented 1 year ago

Hi @jamesboot,

Sorry for the late reply.

Do you have Xcode and Xcode Command Lines tools installed? This provides necessary tools for compiling some R packages. If not, try to install it by typing the script in terminal:

xcode-select --install

Also, could you please check if you have "sf" package installed by

library(sf)

You might also try forcing the installation of the package from source.

devtools::install_github('YingMa0107/CARD', type="source")

Best, Ying

jamesboot commented 1 year ago

No luck I'm afraid. I installed on our institutes linux based HPC instead, that is working.

zhangms1709 commented 10 months ago

Hi @jamesboot, I also have a M1 Mac Monterey, and was able to resolve this issue by reinstalling R with the binary for Apple Silicon, downloading the binary for gfortran by using the command brew install gcc and then installing OpenMP manually based on my Apple Clang version. The first answer for this post helped me a lot as well! Best, Mason