<div dir="ltr"><div>Hi,</div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 20 Feb 2024 at 12:50, Michael Otto <<a href="mailto:michael.otto@data-experts.de" target="_blank">michael.otto@data-experts.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><br><span style="font-size:10pt;font-family:sans-serif">I have now tried
it with 'vcpkg install gdal[tools]'. The tools/apps are there, but they
are not statically linked!</span><br><br><span style="font-size:10pt;font-family:sans-serif">See for example
gdalinfo:</span><br><br><span style="font-size:10pt;font-family:sans-serif">root@vmuser-VirtualBox:/home/vmuser/Git/vcpkg/installed/x64-linux/tools/gdal#
ldd gdalinfo</span><br><span style="font-size:10pt;font-family:sans-serif">
linux-vdso.so.1 (0x00007ffcc0fb3000)</span><br><span style="font-size:10pt;font-family:sans-serif">
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fe3a31ae000)</span><br><span style="font-size:10pt;font-family:sans-serif">
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6
(0x00007fe3a2f82000)</span><br><span style="font-size:10pt;font-family:sans-serif">
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fe3a2d59000)</span><br><span style="font-size:10pt;font-family:sans-serif">
/lib64/ld-linux-x86-64.so.2 (0x00007fe3a6b09000)</span><br><span style="font-size:10pt;font-family:sans-serif">
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1
(0x00007fe3a2d39000)</span></blockquote><div><br></div>You're closer! GDAL itself is statically linked into those executables, as are its dependencies...<br><div><br></div><div>So, I did a test, and I think this is what you need:</div><div><br></div><div><font face="monospace">$ mkdir custom-triplets</font></div><div><font face="monospace">$ cp vcpkg/triplets/x64-linux.cmake custom-triplets/x64-linux-static.cmake</font></div><div><br></div><div>(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)</div><div><br></div><div>Then edit <font face="monospace">custom-triplets/x64-linux-static.cmake</font> and change the following to tell it to statically link the system libraries as well:</div><div><br></div><div><font face="monospace">- <span style="color:rgb(0,0,0)">set(VCPKG_CRT_LINKAGE dynamic)</span></font></div><div><font face="monospace">+ <span style="color:rgb(0,0,0)">set(VCPKG_CRT_LINKAGE static)</span></font><br></div><div><br></div><div>Then build GDAL using your new triplet:</div><div><br></div><div><font face="monospace">$ vcpkg/vcpkg --overlay-triplets=custom-triplets --triplet=x64-linux-static install gdal[tools]</font></div><div><br></div><div>But of course it's not quite that simple... libtiff needs a fix too:</div><div><br></div><div><font face="monospace">$ mkdir custom-ports</font></div><div><font face="monospace">$ cp -a vcpkg/ports/tiff custom-ports/tiff</font></div><div><br></div><div>Then edit <font face="monospace">custom-ports/tiff/FindCMath.patch</font><font face="arial, sans-serif"> and change the following line:</font></div><div><br></div><div><font face="monospace">- +find_library(CMath_LIBRARY NAMES m PATHS ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})</font></div><div><font face="monospace">+ +find_library(CMath_LIBRARY NAMES libm.a m PATHS ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES})<br></font></div><div><br></div><div>(this is super-hacky, there will definitely be a cleaner fix than this, but it works for this purpose right now)</div><div><br></div><div>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:</div><div><br></div><div><div><font face="monospace">$ vcpkg/vcpkg --overlay-triplets=custom-triplets --triplet=x64-linux-static --overlay-ports=custom-ports install gdal[core,tools]</font></div><div><font face="monospace">... go and play in the sunshine ...</font></div><div><font face="monospace">$ vcpkg/installed/x64-linux-static/tools/gdal/gdalinfo --version</font></div><font face="monospace">GDAL 3.8.3, released 2024/01/04</font><div><font face="monospace">$ ldd vcpkg/installed/x64-linux-static/tools/gdal/gdalinfo<br></font></div><font face="monospace"> not a dynamic executable</font><br></div><div><br></div><div>Victory! Now you can hopefully add any other GDAL features/dependencies via the <font face="monospace">gdal[core,tools,...]</font> vcpkg feature options. <i>Fully</i> static binaries aren't really a normal tested output, so you might run into further issues.</div><div><br></div><div>Hope that helps,</div><div><br></div><div>Rob :)</div><div><br></div></div></div>