R语言harmony包安装失败求助:编译报错及多种尝试无效
安装R语言harmony包失败求助
尝试安装harmony包始终失败,已尝试安装二进制版本、手动从归档下载安装,均未成功。以下是安装源码版本时的报错信息:
> install.packages("harmony") There is a binary version available but the source version is later: binary source needs_compilation harmony 0.1.0 0.1.1 TRUE Do you want to install from sources the package which needs compilation? (Yes/no/cancel) yes installing the source package ‘harmony’ trying URL 'https://cran.rstudio.com/src/contrib/harmony_0.1.1.tar.gz' Content type 'application/x-gzip' length 1351250 bytes (1.3 MB) ================================================== downloaded 1.3 MB * installing *source* package ‘harmony’ ... ** package ‘harmony’ successfully unpacked and MD5 sums checked ** using staged installation ** libs clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppProgress/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c RcppExports.cpp -o RcppExports.o In file included from RcppExports.cpp:4: In file included from ./harmony_types.h:1: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/RcppCommon.h:168: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/Rcpp/internal/r_coerce.h:255:7: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations] ::sprintf(buff, "%02x", from); ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.") ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg' #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg))) ^ 1 warning generated. clang++ -arch arm64 -std=gnu++11 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include' -I'/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppProgress/include' -I/opt/R/arm64/include -fPIC -falign-functions=64 -Wall -g -O2 -c harmony.cpp -o harmony.o In file included from harmony.cpp:1: In file included from ./harmony.h:1: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include/RcppArmadillo.h:29: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/RcppArmadillo/include/RcppArmadillo/interface/RcppArmadilloForward.h:25: In file included from /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/RcppCommon.h:168: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/Rcpp/include/Rcpp/internal/r_coerce.h:255:7: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations] ::sprintf(buff, "%02x", from); ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here __deprecated_msg("This function is provided for compatibility reasons only. Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.") ^ /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg' #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg))) ^ 1 warning generated. 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 harmony.so RcppExports.o harmony.o -L/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib -lRblas -L/opt/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.6.0/12.0.1 -L/opt/R/arm64/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/R/arm64/gfortran/lib/gcc/aarch64-apple-darwin20.6.0/12.0.1' ld: warning: directory not found for option '-L/opt/R/arm64/gfortran/lib' ld: library not found for -lgfortran clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [harmony.so] Error 1 ERROR: compilation failed for package ‘harmony’ * removing ‘/Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library/harmony’ Warning in install.packages : installation of package ‘harmony’ had non-zero exit status The downloaded source packages are in ‘/private/var/folders/vv/kfqy3z8d70z_7w2t399bt80w0000gn/T/RtmpzuHWlG/downloaded_packages’
问题原因
报错核心是ld: library not found for -lgfortran,说明系统缺少gfortran编译器,而harmony依赖的RcppArmadillo包需要Fortran编译环境才能完成源码编译。同时日志中找不到gfortran的目录,进一步确认编译环境缺失。
解决步骤
安装gfortran编译环境:
对于Apple Silicon(arm64)架构的Mac,可通过Homebrew安装gcc(包含gfortran):brew install gcc安装完成后,在终端执行
which gfortran验证路径是否存在,确保环境被正确识别。重新安装harmony包:
优先尝试预编译的二进制版本:install.packages("harmony", type = "binary")若二进制版本仍无法安装,确认gfortran环境就绪后,再尝试源码安装:
install.packages("harmony", type = "source")备选方案:
如果上述方法无效,可尝试安装GitHub上的最新版本(需先安装devtools包):install.packages("devtools") devtools::install_github("immunogenomics/harmony")
内容的提问来源于stack exchange,提问作者Sinatra
相关产品推荐
相关产品推荐

