rinstallationalpine-linuxterra

terra package installation failure in alpine


I was trying to install the R package terra in my computer running alpine edge. The installation is unsuccessful with the following message -

/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

I tried

install.packages("terra")

and

remotes::install_github("rspatial/terra")

and

install.packages('terra', repos='https://rspatial.r-universe.dev')

with the same result.

The result of R.version is

           _                           
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  

My alpine version is 3.22.0_alpha20250108

Please guide how I can proceed.


Solution

  • The installation below works, using an interactive Alpine container and gcc.

    docker run --rm -it alpine
    
    apk add R R-dev R-doc g++ gdal-dev proj-dev geos-dev libtbb-dev
    R -s -e 'install.packages(c("remotes", "codetools"), repos="https://cloud.R-project.org")' 
    R -s -e 'remotes::install_github("rspatial/terra")'
    

    Here using the development version of terra because the current CRAN version (1.8-50) does not compile on Alpine for an unrelated reason.

    Others have reported similar problems with LTO/Fortify on Alpine. Disabling either should allow you to compile.