[gdal-dev] CMake: undefined reference to symbol dlerror

Javier Jimenez Shaw j1 at jimenezshaw.com
Fri Apr 29 02:30:50 PDT 2022


We have a link problem on Linux when using GDAL transiently. If we link the
unit tests for a library which depends on GDAL, i.e. an executable which
transiently depends on GDAL through our library, we get the following
linker error:

/usr/bin/ld:
libs/ioimage/tests/CMakeFiles/tests_unit_ioimage.dir/unit/writers/test_geoTiffWriter.cpp.o:
undefined reference to symbol 'dlerror@@GLIBC_2.2.5'
/usr/bin/ld: /lib/x86_64-linux-gnu/libdl.so.2: error adding symbols: DSO
missing from command line

We need to add -ldl to the linker line after GDAL in order to resolve the
linker problem. This can be done when adding the property

  INTERFACE_LINK_LIBRARIES "dl"

to the GDAL::GDAL imported target in GDAL-targets-release.cmake (this is a
generated file); apparently it is not enough to add dl to the
IMPORTED_LINK_DEPENDENT_LIBRARIES_RELEASE property.

Does GDAL depend publicly on dl?
We do not find the proper way to patch GDAL's CMake code to add that
dependency in the generated config file.

Thanks
Javier

.___ ._ ..._ .. . ._.  .___ .. __ . _. . __..  ... .... ._ .__
Entre dos pensamientos racionales
hay infinitos pensamientos irracionales.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20220429/2521cfb0/attachment.html>


More information about the gdal-dev mailing list