Hi, On Tue, 20 Feb 2024 at 12:50, Michael Otto <michael.o...@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@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 :)
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/gdal-dev