Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
homme opened this issue Nov 11, 2021 · 5 comments

Comments

@homme
Copy link

homme commented Nov 11, 2021

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

@rouault
Copy link
Member

rouault commented Nov 11, 2021

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.

@homme
Copy link
Author

homme commented Nov 11, 2021

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.

@dg0yt
Copy link
Contributor

dg0yt commented Dec 8, 2021

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

attilaolah pushed a commit to attilaolah/wasm that referenced this issue Mar 30, 2022
This is a temporary workaround for
OSGeo/gdal#4815.
attilaolah pushed a commit to attilaolah/wasm that referenced this issue Mar 30, 2022
This is a temporary workaround for
OSGeo/gdal#4815.
attilaolah pushed a commit to attilaolah/wasm that referenced this issue Mar 30, 2022
* Remove AEC shared libs.

These interfere with the static linkage of GDAL, breaking the build.

* Update GDAL to 3.4.2.

* Update GEOS to 3.10.2.

Also add an update script to make updating easier.

* Add additional GDAL URL.

* Add GDAL patch.

This is a temporary workaround for
OSGeo/gdal#4815.

* Update README.md.
@vincentsarago
Copy link
Contributor

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

@rouault
Copy link
Member

rouault commented Aug 18, 2022

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

@rouault rouault closed this as completed Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants