Windows环境下需编译旧版R包安装失败问题求助
旧版R包编译安装失败排查与解决建议
环境信息
- Windows 10
- R 4.1.3(2022-03-10)
- Rtools40已安装并配置环境变量至系统PATH
问题描述
为适配运行特定Shiny应用,需安装CRAN归档中的旧版R包,过程中出现编译错误:
初始错误(proxy v0.4-26)
执行安装命令:
install_version("proxy", version = "0.4-26", repos = "http://lib.stat.cmu.edu/R/CRAN/")
核心错误:
C:\Users\Username\Onedrive\Documents\rtools40\mingw32\i686-w64-mingw32\bin\ld.exe: cannot open output file proxy.dll: No such file or directory collect2.exe: error: ld returned 1 exit status no DLL was created ERROR: compilation failed for package 'proxy'
完整编译输出:
Downloading package from url: http://lib.stat.cmu.edu/R/CRAN//src/contrib/Archive/proxy/proxy_0.4-26.tar.gz * installing *source* package 'proxy' ... ** package 'proxy' successfully unpacked and MD5 sums checked ** using staged installation ** libs *** arch - i386 "C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/"gcc -I"C:/Users/Username/ONEDRI~1/DOCUME~1/R-41~1.3/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c apply.c -o apply.o "C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/"gcc -I"C:/Users/Username/ONEDRI~1/DOCUME~1/R-41~1.3/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c arrayIndex.c -o arrayIndex.o "C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/"gcc -I"C:/Users/Username/ONEDRI~1/DOCUME~1/R-41~1.3/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c distance.c -o distance.o distance.c: In function 'ebinary': distance.c:426:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else] if (ISNAN(xy)) ^ distance.c: In function 'cosine': distance.c:473:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else] if (ISNAN(xy)) ^ "C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/"gcc -I"C:/Users/Username/ONEDRI~1/DOCUME~1/R-41~1.3/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c dll.c -o dll.o "C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/"gcc -I"C:/Users/Username/ONEDRI~1/DOCUME~1/R-41~1.3/include" -DNDEBUG -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c util.c -o util.o C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/gcc -shared -s -static-libgcc -o proxy.dll tmp.def apply.o arrayIndex.o distance.o dll.o util.o -LC:/Users/Username/ONEDRI~1/DOCUME~1/R-41~1.3/bin/i386 -lR C:\Users\Username\OneDrive\Documents\rtools40\mingw32\i686-w64-mingw32\bin\ld.exe: cannot open output file proxy.dll: No such file or directory collect2.exe: error: ld returned 1 exit status no DLL was created ERROR: compilation failed for package 'proxy' * removing 'C:/Users/Username/OneDrive/Documents/R-4.1.3/library/proxy' Warning message: In i.p(...) : installation of package ‘C:/Users/Username/AppData/Local/Temp/RtmpSYvdjN/remotes2fb424c4689f/proxy’ had non-zero exit status
更新后错误(processx v3.5.3)
将R、RStudio、Rtools卸载重装至同一目录并设置权限后,部分包成功安装,但processx v3.5.3仍失败:
执行命令:
install_version("processx", version = "3.5.3", repos = "http://lib.stat.cmu.edu/R/CRAN/")
核心错误:
C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find C:/Users/Username/OneDrive: Permission denied C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -: No such file or directory
完整编译输出:
install_version("processx", version = "3.5.3", repos = "http://lib.stat.cmu.edu/R/CRAN/") Downloading package from url: http://lib.stat.cmu.edu/R/CRAN//src/contrib/Archive/processx/processx_3.5.3.tar.gz * installing *source* package 'processx' ... ** package 'processx' successfully unpacked and MD5 sums checked ** using staged installation ** libs *** arch - i386 "C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/"gcc -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -Wall tools/px.c -o tools/px.exe C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find C:/Users/Username/OneDrive: Permission denied C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -: No such file or directory C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find OneDrive: No such file or directory C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find OneDrive: No such file or directory C:/Users/Username/OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find OneDrive/Documents/rtools40/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.3.0/../../../../i686-w64-mingw32/lib/../lib/default-manifest.o: No such file or directory collect2.exe: error: ld returned 1 exit status make: *** [Makevars.win:18: tools/px.exe] Error 1 ERROR: compilation failed for package 'processx' * removing 'C:/Users/Username/OneDrive/Documents/R-4.1.3/library/processx' Warning message: In i.p(...) : installation of package ‘C:/Users/Username/AppData/Local/Temp/RtmpYrC9em/remotes35d836f16857/processx’ had non-zero exit status
无法安装的包列表
- classInt
- cli
- dplyr
- e1071
- farver
- geojsonsf
- htmltools
- openssl
- processx
- proxy
- ps
- raster
- Rcpp
- rlang
- roxygen2
- RSQLite
- s2
- sass
- sf
- sp
- terra
- testthat
- tibble
- xfun
解决建议
- 迁移至无空格路径:将R、Rtools安装到不含空格的目录(如
C:\R\R-4.1.3、C:\Rtools40)。OneDrive路径含空格,编译工具会将空格解析为参数分隔符,导致路径识别错误。 - 优先安装二进制包:对于旧版包,优先使用对应R版本的二进制包安装,执行命令时添加
type="binary"参数,避免源码编译。 - 修改临时目录:设置R的临时目录至无空格路径,执行:
确保临时目录存在且有读写权限。Sys.setenv(TMPDIR="C:/Temp") - 关闭OneDrive同步:编译过程中暂时关闭OneDrive实时同步,避免文件被锁定导致无法生成DLL文件。
- 检查环境变量:确认Rtools的路径已正确添加至系统PATH,且无其他编译工具路径冲突;可通过
Sys.which("gcc")验证gcc路径是否正确。
内容的提问来源于stack exchange,提问作者Pigeoncity22
相关产品推荐
相关产品推荐

