xzhoulab / SPARK

Spatially resolved transcriptomic analysis
GNU General Public License v3.0
46 stars 16 forks source link

Cannot install package on Mac #12

Open Anjan-stat opened 1 year ago

Anjan-stat commented 1 year ago

I'm trying to install SPARK on Mac but getting the following error R version: 4.3.1 MacOC: M1 Pro

if(!require("SPARK", quietly = TRUE)){

  • devtools::install_github('xzhoulab/SPARK')
  • } Downloading GitHub repo xzhoulab/SPARK@HEAD ── R CMD build ───────────────────────────────────────────────────────────────────────────── ✔ checking for file ‘/private/var/folders/vy/r4cjr09n25j20vl1tfz6_glc0000gq/T/RtmpVBFa4H/remotesd7bb8837a4e/xzhoulab-SPARK-a8b4bf2/DESCRIPTION’ ... ─ preparing ‘SPARK’: ✔ checking DESCRIPTION meta-information ... ─ cleaning src ─ installing the package to process help pages

    ─ installing source package ‘SPARK’ ... using staged installation libs using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’ using C++11 using SDK: ‘MacOSX13.3.sdk’ clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppArmadillo/include' -I/opt/R/arm64/include -DARMA_64BIT_WORD=1 -fPIC -falign-functions=64 -Wall -g -O2 -Wall -pedantic -fdiagnostics-color=always -c RcppExports.cpp -o RcppExports.o clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppArmadillo/include' -I/opt/R/arm64/include -DARMA_64BIT_WORD=1 -fPIC -falign-functions=64 -Wall -g -O2 -Wall -pedantic -fdiagnostics-color=always -c rcpparma_hello_world.cpp -o rcpparma_hello_world.o clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/RcppArmadillo/include' -I/opt/R/arm64/include -DARMA_64BIT_WORD=1 -fPIC -falign-functions=64 -Wall -g -O2 -Wall -pedantic -fdiagnostics-color=always -c spark_float.cpp -o spark_float.o clang++ -arch arm64 -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/opt/R/arm64/lib -o SPARK.so RcppExports.o rcpparma_hello_world.o spark_float.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0 -L/opt/gfortran/lib -lgfortran -lemutls_w -lquadmath -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation ld: warning: directory not found for option '-L/opt/gfortran/lib/gcc/aarch64-apple-darwin20.0/12.2.0' ld: warning: directory not found for option '-L/opt/gfortran/lib' ld: library not found for -lgfortran clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [SPARK.so] Error 1 ERROR: compilation failed for package ‘SPARK’ ─ removing ‘/private/var/folders/vy/r4cjr09n25j20vl1tfz6_glc0000gq/T/RtmpLNv8Gq/Rinstd83d752bd7fe/SPARK’

    ERROR: package installation failed Error: Failed to install 'SPARK' from GitHub: ! System command 'R' failed

Streisenberg commented 1 year ago

I have reinstalled gfortran, deleted and reinstalled xcode-build tool, edited and rebuilt the Makevars file (I may have made a mistake here). But I still get the same error. I would be very happy if someone could help. Thank you!

My machine info: Platform : aarch64-apple-darwin20
R.version : 4.2.2 MacOS : Monterey (12.6.5) Chip : Apple M1 Max

ANWANGJHU commented 4 months ago

Here is my solution:

  1. brew install gcc
  2. in terminal, type which gfortran. In my case, it returns /opt/homebrew/bin/gfortran
  3. In terminal, type

    mkdir -p ~/.R  
    nano ~/.R/Makevars
  4. In the ~/.R/Makevars, add
FC = /opt/homebrew/bin/gfortran
F77 = /opt/homebrew/bin/gfortran
FLIBS = -L/opt/homebrew/lib/gcc/14 -lgfortran -lquadmath -lm

Note: /opt/homebrew/lib/gcc is the location of the gcc installed by homebrew, dols /opt/homebrew/lib/gcc in terminal to find which number is available, in my case it is 14

laleoarrow commented 3 months ago

Here is my solution:

  1. brew install gcc
  2. in terminal, type which gfortran. In my case, it returns /opt/homebrew/bin/gfortran
  3. in terminal, type

In terminal, type

mkdir -p ~/.R  
nano ~/.R/Makevars
  1. In the ~/.R/Makevars, add
FC = /opt/homebrew/bin/gfortran
F77 = /opt/homebrew/bin/gfortran
FLIBS = -L/opt/homebrew/lib/gcc/14 -lgfortran -lquadmath -lm

Note: /opt/homebrew/lib/gcc is the location of the gcc installed by homebrew, dols /opt/homebrew/lib/gcc in terminal to find which number is available, in my case it is 14

This approach can be applied to various R packages that require compilation for M-chip MacBooks. Thank you for providing such a valuable solution!