You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Alpine Edge系统中R包terra安装失败求助

解决Alpine Edge上安装R包terra的编译错误

问题背景

运行Alpine Edge(版本3.22.0_alpha20250108),尝试安装R包terra时编译失败,三种安装方式均返回相同错误。

报错信息

/usr/include/fortify/stdio.h: In function '__to_xstring.constprop':
/usr/include/fortify/stdio.h:73:28: error: inlining failed in call to 'always_inline' 'vsnprintf': function body can be overwritten at link time
   73 | _FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
      |                            ^
/usr/include/c++/14.2.0/ext/string_conversions.h:113:32: note: called from here
  113 |       const int __len = __convf(__s, __n, __fmt, __args);
      |                                ^
lto-wrapper: fatal error: c++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
make: *** [/usr/share/R/make/shlib.mk:10: terra.so] Error 1
ERROR: compilation failed for package ‘terra’
* removing ‘/home/ajith/R/x86_64-pc-linux-musl-library/4.5/terra’
Warning message:
In i.p(...) :
  installation of package ‘/tmp/RtmpkokoCo/file213d5e90bf19/terra_1.8-52.tar.gz’ had non-zero exit status

已尝试的安装方式

  • 官方CRAN源安装:
    install.packages("terra")
    
  • GitHub源码安装:
    remotes::install_github("rspatial/terra")
    
  • rspatial专属源安装:
    install.packages('terra', repos='https://rspatial.r-universe.dev')
    

R版本信息

_                           
platform       x86_64-pc-linux-musl        
arch           x86_64                      
os             linux-musl                  
system         x86_64, linux-musl          
status                                     
major          4                           
minor          5.0                         
year           2025                        
month          04                          
day            11                          
svn rev        88135                       
language       R                           
version.string R version 4.5.0 (2025-04-11)
nickname       How About a Twenty-Six  

解决方案

1. 安装系统依赖

首先确保安装terra编译所需的系统库:

sudo apk add gdal-dev proj-dev geos-dev g++ make

2. 临时禁用LTO优化后安装

Alpine的Fortify库与GCC的链接时优化(LTO)存在兼容性冲突,导致内联函数调用失败。临时禁用LTO后再安装:

# 设置编译选项禁用LTO
Sys.setenv(CFLAGS="-fno-lto", CXXFLAGS="-fno-lto")
# 选择任意一种安装方式,例如CRAN源
install.packages("terra")

3. 永久禁用LTO(可选)

若后续安装其他R包也遇到类似问题,可修改R的配置文件永久禁用LTO:
创建或编辑~/.R/Makevars文件,添加以下内容:

CFLAGS += -fno-lto
CXXFLAGS += -fno-lto

保存后重新运行install.packages("terra")即可。

内容的提问来源于stack exchange,提问作者Ajith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 01:11:09