rspatial / terra

R package for spatial data handling https://rspatial.github.io/terra/reference/terra-package.html
GNU General Public License v3.0
543 stars 90 forks source link

Fails to install in Alpine linux #1605

Closed javieriserte closed 2 months ago

javieriserte commented 2 months ago

I'm trying to install terra (1.7-78) from CRAN on Alpine line 3.20

i got this compilation error:

/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++/13.2.1/ext/string_conversions.h:113:32: note: called from here
  113 |       const int __len = __convf(__s, __n, __fmt, __args);
      |                                ^
lto-wrapper: fatal error: g++ returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../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’

I'm trying to build a docker image:

FROM alpine:latest

# Install necessary dependencies
RUN apk add --no-cache \
    bash \
    build-base \
    gcc \
    gfortran \
    perl \
    git \
    curl \
    openblas-dev \
    g++ \
    readline-dev \
    libxt-dev \
    libx11-dev \
    libice-dev \
    libsm-dev \
    libpng-dev \
    jpeg-dev \
    tiff-dev \
    zlib-dev \
    bzip2-dev \
    xz-dev \
    pcre-dev \
    curl-dev \
    cairo-dev \
    pango-dev \
    tcl-dev \
    tk-dev
RUN apk add udunits-dev
RUN apk add gdal-dev proj-dev geos-dev

# Install R
RUN apk add R R-dev

CMD ["R"]

Run the image and then

install.packages(
  "terra",
  repos = "https://cran.rstudio.com"
)

Could you help me with the installation?

rhijmans commented 2 months ago

When/where does this error occur, exactly?

javieriserte commented 2 months ago

Hi @rhijmans...

When/where does this error occur, exactly?

I build the docker image with the Dockerfile above, then i run the docker container, it enters to R, and I execute the install.packages("terra", repos="https://cran.rstudio.com"). The error occurs while building the packages, i think that it is in the linking phase. I can provide a full log of the installation if you wish.

thank you very much !

rhijmans commented 2 months ago

I looks like others have similar problem with LTO on Alpine. See

https://www.google.com/search?q=%22fortify%22+%22error%22+%22LTO%22

So I do not think it is directly related to terra.

javieriserte commented 2 months ago

yes, it seems something between LTO and FORTIFY, disabling any of them with compiler flags allows to compile.