NIEHS / targets_PrestoGP

0 stars 0 forks source link

Compile error in Apple Silicon (M1* and M2*) #11

Closed sigmafelix closed 9 months ago

sigmafelix commented 9 months ago

Hello, my name is Insang Song, and I am an incoming postdoc working with Kyle. I want to report a compile error when I try to build PrestoGP package with the tarball file we are sharing.

Code I tried

install.packages("PrestoGP_0.2.0.9009.tar.gz", type = "source")

── R CMD build ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
# ✔  checking for file ‘/Users/songi2/Downloads/PrestoGP/DESCRIPTION’ ...
# ─  preparing ‘PrestoGP’:
# ✔  checking DESCRIPTION meta-information ...
# ─  cleaning src
# ✔  checking vignette meta-information ...
# ─  checking for LF line-endings in source and make files and shell scripts
# ─  checking for empty or unneeded directories
# ─  looking to see if a ‘data/datalist’ file should be added
# ─  building ‘PrestoGP_0.2.0.9009.tar.gz’
#    Warning: invalid uid value replaced by that for user 'nobody'
#    Warning: invalid gid value replaced by that for user 'nobody'

# Running /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL \
#   /var/folders/58/7rn_bn5d6k3_cxwnzdhswpz4n0z2n9/T//RtmpzS7bVy/PrestoGP_0.2.0.9009.tar.gz \
#   --install-tests 
# * installing to library ‘/Users/songi2/Library/R/arm64/4.3/library’
# * installing *source* package ‘PrestoGP’ ...
# ** 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 -DARMA_64BIT_WORD=1 -I'/Users/songi2/Library/R/arm64/4.3/library/Rcpp/include' -I'/Users/songi2/Library/R/arm64/4.3/library/RcppArmadillo/include' -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c RcppExports.cpp -o RcppExports.o
# clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -DARMA_64BIT_WORD=1 -I'/Users/songi2/Library/R/arm64/4.3/library/Rcpp/include' -I'/Users/songi2/Library/R/arm64/4.3/library/RcppArmadillo/include' -I/opt/R/arm64/include     -fPIC  -falign-functions=64 -Wall -g -O2  -c createUMC.cpp -o createUMC.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 PrestoGP.so RcppExports.o createUMC.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: *** [PrestoGP.so] Error 1
# ERROR: compilation failed for package ‘PrestoGP’
# * removing ‘/Users/songi2/Library/R/arm64/4.3/library/PrestoGP’
# Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
# ! System command 'R' failed

Workaround

After a short googling, I found that the compiler arguments in ./src/MakeVars are not suitable for Apple Silicon and tried the arguments that are suggested in Posit Community Thread:

CXX_STD = CXX11

CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

F77 = /opt/homebrew/bin/gfortran
FC = $(F77)
FLIBS = -L/opt/homebrew/opt/gcc/lib/gcc/current -lgfortran -lquadmath -lm

PKG_CXXFLAGS = $(SHLIB_OPENMP_CXXFLAGS) 
# PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CPPFLAGS = -DARMA_64BIT_WORD=1

Suggestion

Thank you.

sigmafelix commented 9 months ago

I thought that this repo is shared with all sciome folks, which appears not. Will send out this message to the package maintainer in DESCRIPTION file.