[gdal-dev] Antwort: Re: Re: Build static GDAL-Lib and static GDAL-Apps

Michael Otto michael.otto at data-experts.de
Wed Feb 21 03:18:41 PST 2024


Hello Robert,

I've also tried the problem with libtiff, but couldn't solve it. Thanks 
for the tip!

With "gdal[core,tools]" the apps are now static. 
BUT I want to use exactly what is still causing problems: SQLite for the 
creation of MBTiles (possibly GPKG) .

That doesn't seem to work then :o( ?

Is there perhaps still a possibility to use SQLite3 in the static apps if 
I continue my first attempt without vcpkg?

Michael




Von:    "Robert Coup" <robert.coup at koordinates.com>
An:     "Michael Otto" <michael.otto at data-experts.de>
Kopie:  dg0yt at darc.de, gdal-dev at lists.osgeo.org
Datum:  20.02.2024 16:26
Betreff:        Re: Re: [gdal-dev] Build static GDAL-Lib and static 
GDAL-Apps



Hi,

On Tue, 20 Feb 2024 at 12:50, Michael Otto <michael.otto at data-experts.de> 
wrote:

I have now tried it with 'vcpkg install gdal[tools]'. The tools/apps are 
there, but they are not statically linked!

See for example gdalinfo:

root at vmuser-VirtualBox:/home/vmuser/Git/vcpkg/installed/x64-linux/tools/gdal# 
ldd gdalinfo
        linux-vdso.so.1 (0x00007ffcc0fb3000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe3a31ae000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 
(0x00007fe3a2f82000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe3a2d59000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe3a6b09000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 
(0x00007fe3a2d39000)

You're closer! GDAL itself is statically linked into those executables, as 
are its dependencies...

So, I did a test, and I think this is what you need:

$ mkdir custom-triplets
$ cp vcpkg/triplets/x64-linux.cmake custom-triplets/x64-linux-static.cmake

(a "triplet" is a vcpkg configuration for a particular system/cpu/build 
configuration ? linux vs windows vs android, static vs dynamic, x64 vs 
arm, etc)

Then edit custom-triplets/x64-linux-static.cmake and change the following 
to tell it to statically link the system libraries as well:

- set(VCPKG_CRT_LINKAGE dynamic)
+ set(VCPKG_CRT_LINKAGE static)

Then build GDAL using your new triplet:

$ vcpkg/vcpkg --overlay-triplets=custom-triplets 
--triplet=x64-linux-static install gdal[tools]

But of course it's not quite that simple... libtiff needs a fix too:

$ mkdir custom-ports
$ cp -a vcpkg/ports/tiff custom-ports/tiff

Then edit custom-ports/tiff/FindCMath.patch and change the following line:

- +find_library(CMath_LIBRARY NAMES m PATHS 
${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})
+ +find_library(CMath_LIBRARY NAMES libm.a m PATHS 
${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})

(this is super-hacky, there will definitely be a cleaner fix than this, 
but it works for this purpose right now)

And there's a static linking issue with something SQLite-plugin-related in 
GDAL. So lets reduce GDAL to just the core dependencies and the tools:

$ vcpkg/vcpkg --overlay-triplets=custom-triplets 
--triplet=x64-linux-static --overlay-ports=custom-ports install 
gdal[core,tools]
... go and play in the sunshine ...
$ vcpkg/installed/x64-linux-static/tools/gdal/gdalinfo --version
GDAL 3.8.3, released 2024/01/04
$ ldd vcpkg/installed/x64-linux-static/tools/gdal/gdalinfo
not a dynamic executable

Victory! Now you can hopefully add any other GDAL features/dependencies 
via the gdal[core,tools,...] vcpkg feature options. Fully static binaries 
aren't really a normal tested output, so you might run into further 
issues.

Hope that helps,

Rob :)



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240221/ce9f3a34/attachment.htm>


More information about the gdal-dev mailing list