[gdal-dev] Build static GDAL-Lib and static GDAL-Apps

Robert Coup robert.coup at koordinates.com
Tue Feb 13 05:39:34 PST 2024


Hi Michael,

On Tue, 13 Feb 2024 at 07:18, Michael Otto <michael.otto at data-experts.de>
wrote:

> at the moment it's only about the Linux platform. And yes, it should be a
> static compilation with all the necessary dependencies (including libtiff
> and all the others).
>
> I currently use an Ubuntu VM and use an Alpine-Linux Docker container for
> compiling. First a static Geos library is created via cmake, then a static
> Proj library (without Curl, because this currently leads to errors) and
> then Gdal as a static library.
> The basis of the script comes from this source:
> https://github.com/OSGeo/gdal/issues/4815.
> I have updated the version used to the current version and replaced the
> existing './configure' and 'make' commands with cmake.
>
> This is what it looks like:


Thanks, that's helpful :-) Following your script, there's no dynamic
libgdal linked into the app binaries...

# ldd /tmp/mo_gdal_install/bin/gdal_translate
/lib/ld-musl-aarch64.so.1 (0xffffb968b000)
libz.so.1 => /lib/libz.so.1 (0xffffb7e06000)
libtiff.so.5 => /usr/lib/libtiff.so.5 (0xffffb7d87000)
libsqlite3.so.0 => /usr/lib/libsqlite3.so.0 (0xffffb7c80000)
libjpeg.so.8 => /usr/lib/libjpeg.so.8 (0xffffb7c2a000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xffffb7a6a000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0xffffb7a45000)
libc.musl-aarch64.so.1 => /lib/ld-musl-aarch64.so.1 (0xffffb968b000)

If you want it to error instead of creating anything dynamic, add -DCMAKE_
EXE_LINKER_FLAGS=-static to your GDAL configuration. Then you get errors!

[ 95%] Linking CXX executable test_ogrsf
/usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld:
attempted static link of dynamic object `/lib/libz.so'
collect2: error: ld returned 1 exit status
make[2]: *** [apps/CMakeFiles/test_ogrsf.dir/build.make:112:
apps/test_ogrsf] Error 1
make[1]: *** [CMakeFiles/Makefile2:8116:
apps/CMakeFiles/test_ogrsf.dir/all] Error 2
make: *** [Makefile:149: all] Error 2

So you need to add CMake options to specifically point to the static
libraries via -DJPEG_LIBRARY=/usr/lib/libjpegturbo.a and so on. Using the
GDAL internal zlib/libtiff/etc build options might make your life simpler.

Note that GDAL is pretty big! *Each* of gdaltranslate, gdalwarp, etc will
end up at >30MB ...

Rob :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240213/1104b083/attachment.htm>


More information about the gdal-dev mailing list