gdal icon indicating copy to clipboard operation
gdal copied to clipboard

Configuring GDAL 3.4.0 with a statically linked GEOS build fails in Alpine Linux 3.13

Open homme opened this issue 4 years ago • 4 comments

Expected behavior and actual behavior.

I expect to be able to configure and build GDAL against a statically linked GEOS install inside an Alpine Linux container out of the box, but instead I get a configuration error:

<snip ./configure output>
checking for geos-config... /usr/local/bin/geos-config
checking for GEOS version >= 3.1.0... yes
checking for GEOSversion in -lgeos_c... no
configure: error: GEOS library could not be linked

Steps to reproduce the problem.

Place the following geos-static-install.sh script in a scratch directory in a Linux environment with Docker installed, and run:

docker run -it --rm -v $(pwd):/tmp golang:1.17.3-alpine3.13 sh /tmp/geos-static-install.sh
#!/bin/sh

##
# geos-static-install.sh
#
# Reproduce the GDAL build failure in Alpine Linux when using a statically
# linked GEOS.  This script should be run in a scratch directory using docker
# along these lines:
#
# docker run -it --rm -v $(pwd):/tmp golang:1.17.3-alpine3.13 sh /tmp/geos-static-install.sh
#

GDAL_VERSION=3.4.0
PROJ_VERSION=8.2.0
GEOS_VERSION=3.10.1

# Exit on any error.
set -e

# Install build dependencies.
apk add --no-cache \
    wget \
    coreutils \
    build-base \
    unzip

# Install a statically linked verson of Proj.
apk add --no-cache \
    sqlite \
    sqlite-dev \
    sqlite-static \
    tiff \
    tiff-dev
cd /tmp
wget --no-verbose https://download.osgeo.org/proj/proj-${PROJ_VERSION}.tar.gz
tar -xzf proj-${PROJ_VERSION}.tar.gz
cd proj-${PROJ_VERSION}

./configure \
    --disable-shared \
    --enable-static \
    --without-curl \
    --prefix=/usr/local

make -j"$(nproc)"
make install

# Install a statically linked version of GEOS.
apk add --no-cache \
    cmake

cd /tmp
wget --no-verbose https://download.osgeo.org/geos/geos-${GEOS_VERSION}.tar.bz2
tar -xjf geos-${GEOS_VERSION}.tar.bz2
cd geos-${GEOS_VERSION}

mkdir build
cd build
cmake \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=OFF \
    -DBUILD_TESTING=OFF \
    ..

make -j"$(nproc)"
make install

# Install a minimal, statically linked build of GDAL.
apk add --no-cache \
    jpeg-dev \
    libjpeg-turbo-static \
    openssl-libs-static \
    linux-headers

cd /tmp
wget --no-verbose http://download.osgeo.org/gdal/${GDAL_VERSION}/gdal-${GDAL_VERSION}.tar.gz
tar -xzf gdal-${GDAL_VERSION}.tar.gz
cd gdal-${GDAL_VERSION}

# Hack in the correct GEOS linker options to configure: uncomment the following
# line to get a successful GDAL configuration; without it ./configure fails with:
#
# configure: error: GEOS library could not be linked
#
#sed -i 's/GEOS_LIBS="`${GEOS_CONFIG} --ldflags` -lgeos_c"/GEOS_LIBS="`${GEOS_CONFIG} --static-clibs` -lstdc++"/' configure

# Configure GDAL.
./configure \
    --without-ld-shared \
    --disable-shared \
    --enable-static \
    --prefix=/usr/local \
    --with-geos=/usr/local/bin/geos-config \
    --with-geotiff=internal \
    --with-hide-internal-symbols \
    --with-libtiff \
    --with-libz=internal \
    --with-png=internal \
    --with-proj=/usr/local \
    --with-threads \
    --without-cfitsio \
    --without-cryptopp \
    --without-ecw \
    --without-expat \
    --without-fme \
    --without-freexl \
    --without-gif \
    --without-gif \
    --without-gnm \
    --without-grass \
    --without-hdf4 \
    --without-hdf5 \
    --without-idb \
    --without-ingres \
    --without-jasper \
    --without-jp2mrsid \
    --without-kakadu \
    --without-libgrass \
    --without-libkml \
    --without-libtool \
    --without-mrsid \
    --without-mysql \
    --without-netcdf \
    --without-odbc \
    --without-ogdi \
    --without-openjpeg \
    --without-pcidsk \
    --without-pcraster \
    --without-pcre \
    --without-perl \
    --without-pg \
    --without-python \
    --without-qhull \
    --without-sde \
    --without-webp \
    --without-xerces \
    --without-xml2

make -j"$(nproc)"
make install

As can be seen in the script above, running the following on the GDAL ./configure works around the issue:

sed -i 's/GEOS_LIBS="`${GEOS_CONFIG} --ldflags` -lgeos_c"/GEOS_LIBS="`${GEOS_CONFIG} --static-clibs` -lstdc++"/' configure

Operating system

Alpine Linux 3.13 under Docker.

GDAL version and provenance

http://download.osgeo.org/gdal/3.4.0/gdal-3.4.0.tar.gz

homme avatar Nov 11 '21 17:11 homme

My feeling is that static linking is really hard to make work (harder than dynamic linking). People that need it will have to tune things. Given that we are going to migrate to CMake only in a few versions, I don't think we're going to invest a lot in our historic build systems. We'd be better with contributions that make static linking work better with CMake.

rouault avatar Nov 11 '21 18:11 rouault

Thanks, that sounds fine to me: I'm happy with the current workaround for now and can revisit this when CMake only comes along with the aim of getting a proper fix in.

I agree with the sentiment that static linking is generally harder than dynamic! In this case the extra effort is worth it as we end up with docker images at around 30MB rather than over 1GB.

homme avatar Nov 11 '21 18:11 homme

In vcpkg, you will find a static build of gdal for linux. It includes a lot of patching to configure.ac to make use of pkgconfig files. (vcpkg officially only supports static linkage on linux and macos. It also builds debug and release within a single install tree.) https://vcpkg.io

dg0yt avatar Dec 08 '21 06:12 dg0yt

I'm hitting the same issue when trying to build GDAL 3.4.3 (using GitHub release/3.4 branch).

The issue I have is that I'm trying to force the lib to be in /opt/lib but from what I understand the latest version of geos (or because of the arch) will install its lib in /opt/lib64. To overcome this I've forced geos install with cmake3 -DCMAKE_INSTALL_PREFIX=/opt -DCMAKE_INSTALL_LIBDIR=/opt/lib -DCMAKE_BUILD_TYPE=Release .. \ but then I get the GDAL configure issue #32 138.3 configure: error: GEOS library could not be linked

I've tried the proposed patch without success :-(

Dockerfile can be found here: https://gist.github.com/vincentsarago/f48132e715cac40ecb5c15f93b6a30b6

vincentsarago avatar May 10 '22 09:05 vincentsarago

closing as autoconf has been removed from master and replaced by cmake

rouault avatar Aug 18 '22 16:08 rouault