0

Context:

I built an a.out on my local system with a modern CMake project adding a dependency to a shared library:

find_package(GDAL QUIET)

if(GDAL_FOUND)
  get_property(_loc TARGET GDAL::GDAL PROPERTY LOCATION)
  message(STATUS "Found GDAL: ${_loc} (version ${GDAL_VERSION})")
  add_library(gdal_external INTERFACE)  # dummy

Everything works fine on my system. Now I want to distribute the a.out to systems that don't have the dependency (the .so).

Problem:

I copied the binary a.out on a cluster, and when I execute it, I get the following error: error while loading shared libraries: libgdal.so.26: cannot open shared object file: No such file or directory.

Possible solution and other considerations

  • Installing the dependencies on the cluster, but I don't have admin rights on this server
  • even if I had the dependency installed by the staff, the same problem will arise later when I will ship the binary to possible users
  • I can't ask future users to manage dependencies and build from sources.
  • It seems to me that I should embed all the dependencies in the same executable, that is using a static library rather than share
  • Executable size or memory issues are not the priority

How do I indicate CMake to use the static version of a library ?

WaterFox
  • 850
  • 6
  • 18
  • 1
    So, do you have **static** GDAL library? Obtaining it should obviously be the first step for linking GDAL statically.. – Tsyvarev Dec 17 '20 at 20:35
  • @Tsyvarev, I don't have the static library *yet*, just because I don't want to mess up with my system again. I know I can follow [this idea](https://stackoverflow.com/questions/53511533/building-gdal-with-all-libraries-static) to get it done, but I don't want to engage this path without knowing where it leads and how much time it will cost me :) – WaterFox Dec 17 '20 at 21:50
  • 1
    If you build and install GDAL statically into some custom installation prefix, then could ask CMake to search that prefix with `find_package(GDAL)`. So CMake will find static libraries. Is it what you ask? – Tsyvarev Dec 17 '20 at 22:24
  • @Tsyvarev yes this is what I ask. Once I get the static library, how do I ask CMake to find the static version. – WaterFox Dec 17 '20 at 23:14
  • 1
    In the [documentation](https://cmake.org/cmake/help/latest/module/FindGDAL.html) you may find `GDAL_DIR` and `GDAL_ROOT` variables, using which you could hint CMake about CGAL location. Variable [CMAKE_PREFIX_PATH](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html) works for this purpose too. (The variable `CMAKE_PREFIX_PATH` affects on internal functionality of `find_package`, so it is not noted in the documentation for specific "FindXXX" modules.) – Tsyvarev Dec 17 '20 at 23:38
  • If I understand well, CMake will build whatever it finds at the location ? If the dependency code is embedded into the executable depends only on if what CMake finds is a share library or a static library? I would have thought one would required to add a `STATIC` keyword somewhere in the CMake project. – WaterFox Dec 18 '20 at 00:14

0 Answers0