OSGeo / libgeotiff

Official repository of the libgeotiff project
182 stars 70 forks source link

Error linking TIFF on Ubuntu #20

Open NikkittaP opened 5 years ago

NikkittaP commented 5 years ago

I use libgeotiff 1.5.1 and libtiff 4.0.10. To build everything I use CMake and make.

TIFF: cmake -G 'Unix Makefiles' ../../ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/nikita/OSG/test_osg/install/libtiff/Release -DZLIB_INCLUDE_DIR=/home/nikita/OSG/test_osg/install/zlib/Release/include/ -DZLIB_LIBRARY_RELEASE=/home/nikita/OSG/test_osg/install/zlib/Release/lib/libz.so -DJPEG_INCLUDE_DIR=/home/nikita/OSG/test_osg/install/libjpeg/Release/include/ -DJPEG_LIBRARY=/home/nikita/OSG/test_osg/install/libjpeg/Release/lib/libjpeg.so

libgeotiff: cmake -G 'Unix Makefiles' ../../ -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/nikita/OSG/test_osg/install/libgeotiff/Release -DWITH_UTILITIES=OFF -DWITH_JPEG=ON -DWITH_TIFF=ON -DWITH_ZLIB=ON -DPROJ_INCLUDE_DIR=/home/nikita/OSG/test_osg/install/proj/Release/include/ -DPROJ_LIBRARY=/home/nikita/OSG/test_osg/install/proj/Release/lib/libproj.so -DZLIB_INCLUDE_DIR=/home/nikita/OSG/test_osg/install/zlib/Release/include/ -DZLIB_LIBRARY_RELEASE=/home/nikita/OSG/test_osg/install/zlib/Release/lib/libz.so -DJPEG_INCLUDE_DIR=/home/nikita/OSG/test_osg/install/libjpeg/Release/include/ -DJPEG_LIBRARY=/home/nikita/OSG/test_osg/install/libjpeg/Release/lib/libjpeg.so -DTIFF_INCLUDE_DIR=/home/nikita/OSG/test_osg/install/libtiff/Release/include/ -DTIFF_LIBRARY_RELEASE=/home/nikita/OSG/test_osg/install/libtiff/Release/lib/libtiff.so

And while configuring CMake for geotiff I get the following error:

Found TIFF: /home/nikita/OSG/test_osg/install/libtiff/Release/lib/libtiff.so.5.4.0 (found version "4.0.10") 
CMake Error at CMakeLists.txt:182 (MESSAGE):
  Failed to link with libtiff - TIFFOpen function not found

The same sources on Windows with CMake and MSVC 2015 are built properly with no errors.

NikkittaP commented 5 years ago

I'm still facing the same problem on Ubuntu 18.04. Any ideas?

NikkittaP commented 5 years ago

Oookaay, here is my solution for now:

In the main CMakeLists.txt I commented out lines 179-189. These lines checks functions in TIFF library and somehow it fails on Linux. I will add more info if I have any problems while using this built libgeotiff library.

attilaolah commented 3 years ago

I think this can be fixed by adding this line to CMakeLists.txt:

cmake_policy(SET CMP0075 NEW)

Specifically, the CMake checks don't seem to honor the CMAKE_REQUIRED_LIBRARIES. This causes failure when you try to link against libraries on your system.

attilaolah commented 3 years ago

Another option is to pass -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY to cmake.

lastant commented 1 year ago

For me this happened because cmake was looking for libtiff using FIND_PACKAGE and found it, but only the variables TIFF_FOUND, TIFF_DIR, TIFF_VERSION were set, the variable TIFF_LIBRARIES was not, but was needed. I actually had to explicitly set the libraries in the /usr/share/cmake-3.22/Modules/CheckFunctionExists.cmake file to circumvent the issue.

mathstuf commented 12 months ago

Yes, the CMake package generated by libtiff upstream does not provide TIFF_LIBRARIES, so nothing ends up being passed to the try_compile for linking.in order to pass. The check needs reworked to handle this case. Something like this may be fine:

if (NOT TIFF_LIBRARIES AND TARGET TIFF::tiff)
  get_property(TIFF_LIBRARIES TARGET TIFF::tiff PROPERTY LOCATION)
  # request a `STATIC` library in `try_compile` as dependent libraries are not provided this way?
endif ()