mapnik/mapnik — Issue #1105: configure time check for gdal libtiff linking problem
Author: springmeyer
Created: 2012-02-27 18:16:52+00:00
State: open

Gdal bundles and configures by default against a bigtiff-enabled libtiff - aka unreleased libtiff 4.x. Mapnik by default links against the system libtiff, which will be libtiff 3.x, for image i/o. If the mapnik gdal plugin is also compiled then when it is loaded dynamically symbols between the system libtiff and gdal's bundled copy may clash, leading to odd crashes when trying to render tiffs through gdal.

Therefore recent versions of GDAL try to catch this condition and warn the user. The symptom is seen when GDAL spits out:

`Warning 1: libtiff version mismatch : You're linking against libtiff 3.X, but GDAL has been compiled against libtiff >= 4.0.0`

One solution to this is to recompile gdal against the system libtiff. But this is not usually ideal because this leads to dropped bigtiff support (ability to read rasters over 4 gb). The solution is detailed at: http://www.gravitystorm.co.uk/shine/archives/2011/08/09/dealing-with-gdal-and-mapnik/

Another potential solution is to have mapnik's configure scripts detect if GDAL is using internal, static linking against libtiff4 and if so then to use the libtiff symbols available libgdal directly. Normally libmapnik does not link libgdal (only the gdal.input plugin). But we could pass `-lgdal` instead of `-ltiff` when linking mapnik if the user happens to be requesting that the Mapnik GDAL plugin be compiled.

The configure check could do something like:

```cpp
#include
#include
#include "cpl_error.h"

/*
note: -ltiff must come before -lgdal
clang++ -o tiff-test tiff-test.cpp -ltiff `gdal-config --libs`
*/

CPL_C_START
int GTiffOneTimeInit();
CPL_C_END

int main()
{

// print blank line to hide Warning 1: libtiff version mismatch from scons output
GTiffOneTimeInit();
std::string last_error(CPLGetLastErrorMsg());
if (last_error.find("libtiff version mismatch") != std::string::npos)
{
return 0;
}

return 1;
}
```